in reply to Learning Perl 3 questions (misc)
As for the /gi, adding /g to the end of a regular expression makes it so that it won't give up after the first match, and will do it to all the matches that it could. Check out these two lines:
perl -e 'my $x = "fredfred"; $x =~ s/(fred)/\U$1/; print $x' FREDfred
perl -e 'my $x = "fredfred"; $x =~ s/(fred)/\U$1/g; print $x' FREDFRED
In the first example, the $x variable was set to "fredfred", then the first match it could find was uppercased. In the second, all the matches it could find were uppercased.
The /i at the end means "ignore case", which means if $x = "fRedFREd" or $x = "FRedFrED" the regex would still match.
You are right about the join code. However, it all comes down to what you find most convenient. If you had to add 14 and 15 to that list of numbers, which one would be easier to work with?
Hope this helps.
|
|---|