in reply to Re: Directory checking on Windows XP
in thread Directory checking on Windows XP

,p>Bingo!

I forgot to chomp($entry)!

What a rookie mistake I made! Thank you. I was thinking that readdir() didn't put CRLFs in...but apparently it does. When I added in the chomp($entry) the code works perfectly!

Even while debugging I failed to see the extra characters; I was too focused on the non-CRLF names and characters...looking for unexpected included extra spaces, etc.

Thank you apl. And thanks to everyone who responded. Your support and time mean the world to me and I am sincerely embarassed by my mistake and appreciate your time and efforts.

ack Albuquerque, NM

Replies are listed 'Best First'.
Re^3: Directory checking on Windows XP
by ikegami (Patriarch) on Sep 22, 2008 at 06:09 UTC

    chomp removes $/ which is just LF, not CRLF. Yes, even on Windows. So chomp wouldn't fix appended CRLF, just appended LF.

    use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Useqq = 1; print(Dumper($/)); # "\n" $_ = "abc\x0D\x0A"; print(Dumper($_)); # "abc\r\n" chomp; print(Dumper($_)); # "abc\r"

    But readdir doesn't append CRLF or LF to the file names it returns. Not unless you have a broken perl.

    >copy nul foo 1 file(s) copied. >copy nul bar 1 file(s) copied. >perl -e"opendir $dh, '.' or die; print readdir $dh" ...barfoo

    Tested with Perl 5.6.0, 5.6.1, 5.8.0, 5.8.8 and 5.10.0.

      Ah! Most interesting...! So now I'm curious about why, when I print out $entry, I don't see the LF. Does the \n metacharacter at the end of my print character string somehow obscure the LF in $entry?

      I will explore that on my own, you have already given me so much of your time and I really will learn it better if I struggle with it myself.

      ikegami, thank you.

      ack Albuquerque, NM

        Does the \n metacharacter at the end of my print character string somehow obscure the LF in $entry?

        The code you posted contains no variable named $entry.

        It's definitely possible that it's easy to overlook that $var ends with \n when doing print("$var\n"), but both \n will have an effect.

      ikegami, I just re-read your response and must admit that I am now confused and a bit curious...not by your response (which is clear and wise), but by the result I just got. I just re-tested my old code (without the chomp()) and it still fails. But when I run it with the chomp(), it works.

      Your information regarding readdir() is, in fact, what I, too, had assumed (more from naivete rather than real knowlege) in the original code and was why I hadn't thought to do the chomp()).

      Unfortunately, now I'm not sure I understand why adding in the chomp() would matter...would make the code succeed.

      I think it's time to go back and dig into the original version of my code (i.e., pre-chomp() version) and see if I can ferret out what is going on. I'm sure it is a mistake that I've made in the code; I'm just not sure where to start beyond what I'd already done. But is should be a good learning and growing experience for me.

      For what it's worth, I'm running on Perl 5.8.0

      Again, thanks, ikegami

      ack Albuquerque, NM