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:

Contents = **** Fnord **** Contents = **** Plugh **** Contents = **** Fnord Plugh ****
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.
Now I can always just call file_contents() from that point in the append block and throw away the result. Does anyone have a more elegant solution?
Again, note - this only happens on Solaris, not Linux.

Update:Yep, the close ARGV works - nice and elegant, thanks.

Peter Scott
Perl Medic

In reply to Weird 5.8.8 Solaris <> bug by peters

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.