in reply to memory variables (chp. 9 & 10 Learning Perl 3)
Here's an example:
$string = 'my name is mister smith'; if($string =~ /(mr\.|mister (\w+))/){ # if the string contains either 'mr.' or # 'mister', then a space, then some word chars # matching for instance 'mister jones' but not # 'hey mister!' print "surname is $2"; # $1 contains the whole thing, $2 just the surname }
I came up with this one for an auto-html syntax thing.
Paste the URL and put optional link text after it in brackets.
$text='Learning Perl? http://www.perlmonks.org/ <this> is the place'; $text =~ s!(http://\S+) (\s+<([^>]+)>)? ! defined($3)? qq(<a href="$1">$3</a>): qq(<a href="$1">$1</a>) !gex; print $text;
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print
|
|---|