Tutorial by Examples

The =~ operator attempts to match a regular expression (set apart by /) to a string: my $str = "hello world"; print "Hi, yourself!\n" if $str =~ /^hello/; /^hello/ is the actual regular expression. The ^ is a special character that tells the regular expression to start with ...
What's between \Q and \E is treated as normal characters #!/usr/bin/perl my $str = "hello.it's.me"; my @test = ( "hello.it's.me", "hello/it's!me", ); sub ismatched($) { $_[0] ? "MATCHED!" : "DID NOT MATCH!" } my @match = ( ...
Generally, it's not a good idea to use a regular expression to parse a complex structure. But it can be done. For instance, you might want to load data into hive table and fields are separated by comma but complex types like array are separated by a "|". Files contain records with all fiel...
s/foo/bar/; # replace "foo" with "bar" in $_ my $foo = "foo"; $foo =~ s/foo/bar/; # do the above on a different variable using the binding operator =~ s~ foo ~ bar ~; # using ~ as a delimiter $foo = s/foo/bar/r; # non-destructive r flag: returns the repl...

Page 1 of 1