If CGI.pm calls binmode on STDIN on your platform (and I will suspect that it does), Perl won't internally translate the \r\n sequence into \n. That's the point of binmode.

In that case, chomp will remove the \n, but there will still be a trailing \r at the end of the filename.

Your error message ought to print "Cannot open $directory" and then the contents of $!. Since you're only getting $!, if you've reported the entire error message, it indicates that Perl printed the first part of the error, hit the \r, moved back to the first column, and printed the second half:

my ($one, $two) = qw( one two ); print "$one\r$two\n";
The simple fix is to strip out any carriage returns with a transliteration: $directory =~ tr/\r//d;

As a side note, I usually debug variables by printing them like print "Directory: ($directory)\n";. That helps make whitespace apparent.


In reply to Re: WinNT Opendir with CGI by chromatic
in thread WinNT Opendir with CGI by loosid

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.