Reputation: 42421
The documentation for the /m
option in perlre says this:
Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string.
But this example seems to indicate that /^/
and /^/m
behave the same way. What am I misunderstanding?
use strict;
no warnings; # Ignore warning about implicit split to @_
my $x = " \n \n ";
print scalar(split /^/m, $x), scalar(split /$/m, $x), "\n"; # 33
print scalar(split /^/, $x), scalar(split /$/, $x), "\n"; # 31
Upvotes: 2
Views: 190
Reputation: 98398
Yes, /^/
is different than /^/m
, but because /^/
would be useless when used with split
, it (for split
only) automatically becomes /^/m
. This is documented in perldoc -f split.
This is the kind of surprising DWIM that would probably not be included in perl if we had to do it all over again.
Upvotes: 19