peters has asked for the wisdom of the Perl Monks concerning the following question:
I've got a strange problem with using <> on perl 5.8.8 on Solaris. It doesn't occur on 5.8.8 or 5.10.0 on Linux. Upgrading is not an option; I have a clumsy workaround and am looking for something better. Here's demonstration code:
use strict; use warnings; my $FILE = "/tmp/foo"; { open my $fh, ">", $FILE or die; print {$fh} "Fnord\n" } print "Contents =\n****\n", file_contents(), "****\n"; { open my $fh, '>>', $FILE or die $!; print {$fh} "Plugh\n" } print "Contents =\n****\n", file_contents(), "****\n"; print "Contents =\n****\n", file_contents(), "****\n"; sub file_contents { local @ARGV = $FILE; local $/; my $contents = <>; return $contents; }
And here's the output:
The problem is that the second print of the file contents yields only the last line that was inserted, not both lines. I've been focusing on the end of the block containing the append. I've tried explicitly assigning () to @ARGV, explicitly closing $fh, explicitly undef'ing $fh.Contents = **** Fnord **** Contents = **** Plugh **** Contents = **** Fnord Plugh ****
Update:Yep, the close ARGV works - nice and elegant, thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Weird 5.8.8 Solaris <> bug (close)
by tye (Sage) on Oct 29, 2009 at 02:11 UTC | |
|
Re: Weird 5.8.8 Solaris <> bug
by gmargo (Hermit) on Oct 29, 2009 at 02:27 UTC | |
|
Re: Weird 5.8.8 Solaris <> bug
by jakobi (Pilgrim) on Oct 29, 2009 at 07:10 UTC |