After playing with this question for a while this morning I have discovered some strange behaviour that appears to be related to the CGI module on Win32. Basically it appears to break reading from STDIN. I'm very bad at explaining things so take a look at this code:
#!/usr/bin/perl -w use strict; use CGI; my $indir = <STDIN>; chomp $indir; my $dir = 'c:/temp'; print "Opening $dir\n"; opendir (DIR, $dir) || die "Could not open dir: $!"; my @array=readdir (DIR); closedir (DIR); print "$_\n" foreach @array; print "Opening $indir\n"; opendir (INDIR, $indir) || die "Could not open dir: $!"; my @inarray=readdir (INDIR); closedir (INDIR); print "$_\n" foreach @inarray;
This works fine on a Linux machine but dies during the $indir open in the second part on a Win32 machine, all the $dir bits work just fine. Poking at the CGI.pm I notice this little bit of code:
if ($needs_binmode) { $CGI::DefaultClass->binmode(main::STDOUT); $CGI::DefaultClass->binmode(main::STDIN); $CGI::DefaultClass->binmode(main::STDERR); }
If I uncomment those then both opendirs work fine. Can anybody enlighten me as to why this is happening?

In reply to Win32 CGI breaks STDIN? by the_slycer

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.