Subject: Re: [Boston.pm] s/// with side effects?

SR>   print "\t<" . ("tri state airport" =~ m//) . ">\n";
SR>   $line =~ s/\r//gs;
SR>   print "\t<" . ("tri state airport" =~ m//) . ">\n";


uri> you have run into a very obscure and now deprecated and soon to
uri> be replaced corner of perl. the empty regex actually doesn't
uri> match the empty string in m// (it does in split //!).

Obscure indeed.  It's taken me many years to stumble over this one :)


uri> from perldoc perlop:
uri> uri> If the PATTERN evaluates to the empty string, the last
uri>   successfully matched regular expression is used instead.

kag> m// only sometimes means "match the empty pattern".  Depending on
kag> context, it can also mean "match the same pattern again".

kag> The first m// has no previous pattern to reuse, so works as
kag> "match the empty pattern".  The second does have a previous
kag> pattern, from the substitution, so works as m/\r/.  "tri state
kag> airport" lacks carriage returns, so doesn't match.


Ken and Uri - thanks.  That explains things perfectly.


Steve

_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to