Subject: Re: [Boston.pm] s/// with side effects?
"SB" == Samuel Baldwin <[email protected]> writes:
SB> A bit of a side question; when would you ever want to try and match an
SB> empty regex? Wouldn't it be semantically saner to use defined?
John Macdonald <[email protected]> replies:
A sane use would be as a parameter to a function that takes a
filter pattern, in a case where you don't want to filter anything
out. Since // always matches, it turns the match into a no-op.
My case was slightly different. Instead of
("some string" =~ m//)
the actual construct was
($some_string =~ m/$foo/)
The "bug" that my co-worker and I were looking at came from code that
allowed $foo to take on the value "". That was easy to fix; but I was
intrigued at getting different answers from successive evaluations of
m//.
Yes, we could break into a long discussion about the importance of
thoroughly sanitizing external data, but let's not :)
Steve
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm