Good answer, one error though, m// is not an empty pattern, it is the last pattern to successfully match, split gets special dispensation so that split m//, $stuff does split on an empty pattern.
From the split reference: As a special case for split, using the empty pattern // specifically matches only the null string, and is not be confused with the regular use of // to mean "the last successful pattern match". So, for split, the following:
print join(':', split(//, 'hi there'));
produces the output 'h:i: :t:h:e:r:e'.
| [reply] [d/l] |
Cripes, I'd never realised that, thanks for pointing it out. I had to write a little piece of code to prove it to myself.
$ perl -le '
> $s1 = q{catDOGfish};
> $s2 = q{xxYYYzz};
> print $1 if $s1 =~ m{([A-Z]+)};
> print $1 if $s1 =~ m{([0-9]+)};
> print $1 if $s2 =~ m{};'
DOG
YYY
$
Fancy not knowing that after all this time! Thanks again,
JohnGG | [reply] [d/l] |