Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: I go crazy with windows filenames with spaces!

by Anonymous Monk
on Jan 19, 2010 at 15:09 UTC ( #818208=note: print w/ replies, xml ) Need Help??


in reply to Re: I go crazy with windows filenames with spaces!
in thread I go crazy with windows filenames with spaces!

All right! My first code works if I chop what I get from cd, so:

$path = `cd`; chop $path; opendir MYDIR, $path; print "Path:\n$path\n"; while ( $file = readdir(MYDIR)) { + print "File: ", $file, "\n"; }
One can really go mad when dealing with filenames in Windows. Greetings Bill... Thanks!


Comment on Re^2: I go crazy with windows filenames with spaces!
Download Code
Re^3: I go crazy with windows filenames with spaces!
by Corion (Pope) on Jan 19, 2010 at 15:11 UTC

    Your problem is less with Windows but with your roundabout way of using Perl as if it were a command shell instead of using the Perl built-in ways.

      I try to use module when coding in Perl only if there is no other way. I just like to know what is happening in my script in every line. If you "overuse" other people's work you can run into trouble one day :)

      (This is my general opinion about mass using modules/classes when developing new application, we can discuss it here if you want.)
        Wow, step away from the computer, its someone elses module :P

        Cwd is a CORE module, it comes with perl.

        I try to use module when coding in Perl only if there is no other way.

        You'd rather use code that's only as good your skills can produce, code that hasn't had time to get vetted and improved. And you think you'll run into less trouble?

Re^3: I go crazy with windows filenames with spaces!
by ikegami (Pope) on Jan 19, 2010 at 15:33 UTC

    None of the problems you experienced are in any way related to Windows. The program would behave identically on any other OS*.

    {Bashing someone else for your own errors}--

    The space you are getting is not a space at all. It's the linefeed at the end of the line cd outputted. chomp is a better way of removing it.

    * — Actually, it'll work even less because `cd` won't work on other OSes. It only works on Windows because of a bug in the Windows part of Perl. If `cd` did work elsewhere, the rest of the program would behave identically.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://818208]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-09-16 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (33 votes), past polls