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
Yes,
/^/is different than/^/m, but because/^/would be useless when used withsplit, it (forsplitonly) 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.