Perl print matched pattern

perl Add comments

“Is Perl Just Another Hack” =~ /\w+ (\w+) (\w+) (\w+)(er) (\w+)/;
print $1; # Prints Perl – the thing captured by the first brackets.
print $2; # Prints Just – the thing captured by the second brackets.
print $3; # Prints Anoth – the thing captured by the third brackets.
print $4; # Prints er – the thing captured by the fourth brackets.
print $5; # Prints Hack – the thing captured by the fifth brackets.
print “$2 $3$4 $1 $5$4″; # Prints “Just Another Perl Hacker”.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in