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.In reply to pattern match against in-memory file causes odd behavior by kixix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |