>>>>> "SR" == Steve Revilak <[email protected]> writes:
SR> print "\t<" . ("tri state airport" =~ m//) . ">\n";
SR> $line =~ s/\r//gs;
SR> print "\t<" . ("tri state airport" =~ m//) . ">\n";
SR> With a slight alteration (changing s/// to tr///), we get a different
SR> result.
SR> my $line = "hello world\r";
SR> print "\t<" . ("tri state airport" =~ m//) . ">\n";
SR> $line =~ tr/\r//d;
SR> print "\t<" . ("tri state airport" =~ m//) . ">\n";
you have run into a very obscure and now deprecated and soon to be
replaced corner of perl. the empty regex actually doesn't match the
empty string in m// (it does in split //!).
from perldoc perlop:
If the PATTERN evaluates to the empty string, the last
successfully matched regular expression is used instead. In
this case, only the "g" and "c" flags on the empty pattern is
honoured - the other flags are taken from the original pattern.
If no match has previously succeeded, this will (silently) act
instead as a genuine empty pattern (which will always match).
Note that it's possible to confuse Perl into thinking "//" (the
empty regex) is really "//" (the defined-or operator). Perl is
usually pretty good about this, but some pathological cases
might trigger this, such as "$a///" (is that "($a) / (//)" or
"$a // /"?) and "print $fh //" ("print $fh(//" or "print($fh
//"?). In all of these examples, Perl will assume you meant
defined-or. If you meant the empty regex, just use parentheses
or spaces to disambiguate, or even prefix the empty regex with
an "m" (so "//" becomes "m//").
your use of m// forced it to be the empty regex and you got what the
above says. the s/// worked so the second m// in the first example reran
the regex of /\r/. the tr/// is NOT a regex so it didn't affect the m//.
note that // now means 'defined or' in very recent perls.
uri
--
Uri Guttman ------ [email protected] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm