kixix has asked for the wisdom of the Perl Monks concerning the following question:
This is a cross-post from this SO question - see that for more details
I am printing to an in-memory file, like so:my $memory_file; my $fh; open ($fh, '>', \$memory_file); print $fh "abc"; if( $memory_file =~ m/^.*$/ ) { print "yes\n" } else { print "no\n" }
For me, on perl 5.14.1, the above prints 'no', which is not what I expect.
Interestingly replacing $ with \z causes it to work, though \Z does not.
Also interestingly, if I assign to a temporary variable before doing the pattern match (and do the match against that temporary variable), it works as expected.
Does anyone have an explanation for this odd behavior? Is this documented anywhere? Or is it a bug?
Update: I logged this as a bug via perlbug. Thanks everyone for the investigation.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pattern match against in-memory file causes odd behavior
by wrog (Friar) on Dec 28, 2011 at 05:51 UTC | |
by Eliya (Vicar) on Dec 28, 2011 at 06:15 UTC | |
|
Re: pattern match against in-memory file causes odd behavior
by juster (Friar) on Dec 28, 2011 at 02:20 UTC | |
|
Re: pattern match against in-memory file causes odd behavior
by Eliya (Vicar) on Dec 28, 2011 at 00:56 UTC | |
|
Re: pattern match against in-memory file causes odd behavior
by TJPride (Pilgrim) on Dec 28, 2011 at 01:03 UTC | |
|
Re: pattern match against in-memory file causes odd behavior
by choroba (Cardinal) on Dec 28, 2011 at 14:45 UTC |