[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] $_=$l[rand@l]; (fwd)



John Porter writes:
|> > @ARGV='iMax:Documents:Info:lwall-quotes.txt';$/='%%
|> > ';@l=<>;$_=$l[rand@l];chomp;print
|> Two characters:
|> @ARGV='iMax:Documents:Info:lwall-quotes.txt';$/='%%
|> ';@l=<>;print$l[rand@l]=~/(.*)/
|To which Ronald J Kimball responded by saying that the
|semantics of /(.*)/ is different because $/ has been
|changed.
|I was not able to confirm that assertion; my tests
|showed /(.*)/ still considers . (dot) to exclude \n
|specifically, not $/.

That's correct, but it's also the problem. When Ronald said the semantics of
/(.*)/ are different, he meant different than chomp when $/ isn't a newline
(or I suppose multiple newlines). Here's a different example that might be a
little clearer:

$/ = "%%\n";
$_ = "hello, earth%%\n";
print /(.*)/;
chomp;
print;

The regexp only strips the newline, chomp strips $/, so the second attempt
above will print the quote but with the %% on the end.

Brian

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe