In Perl, is there a difference between / ^ / and / ^ / t?
The documentation for the option /m
in perlre says this:
Treat a string as multiple lines. With is, change "^" and "$" to match the beginning or end of a string to match the beginning or end of any string anywhere within the string.
But this example shows that /^/
they /^/m
behave the same way. What? I do not understand?
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
source to share
Yes, it /^/
is different from /^/m
, but since it is /^/
useless when used with split
, it (for only split
) automatically becomes /^/m
. This is documented in perldoc -f split .
This is that awesome DWIM that probably wouldn't be included in perl if we had to do it over and over again.
source to share