Are you actually trying to (re)open stdin or stdout, or where those just the name you picked for your filehandles? From your code it looks like you are doing normal file operations. If that is the case it is not a good idea to name your handles STDIN etc. At best it creates confusing code, at worst it will cause unexpected results.

As armstd, it looks like your syntax may be confusing the compiler not to mention other programmers trying to read your code. Instead why not write:

my @open_specs = ( { 'handle' => undef, 'file' => 'input.txt', 'mode' => '<', } # Fill in more files/modes here ); foreach my $open_spec (@open_specs) { my($file, $mode) = @$open_spec{'file', 'mode'}; # hash slic +e; my $fh; open $fh, $mode, $file or die "Error opening file $file in mode $m +ode $!"; $open_spec->{'handle'} = $fh; }

In reply to Re: Pitfalls met while opening multiple files by chrestomanci
in thread Pitfalls met while opening multiple files by foobarrior

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.