Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Re: Re: opendir and directories that have spaces in them

by bikeNomad (Priest)
on Aug 14, 2001 at 04:19 UTC ( #104640=note: print w/replies, xml ) Need Help??

in reply to Re: Re: opendir and directories that have spaces in them
in thread opendir and directories that have spaces in them

I'm not sure why you're doing a few things there:
  • taking a list and returning it spliced together as a string, only to split it again (why not return two array refs instead?)
  • doing a split just to find out if there's a space character in a filename (why not just use m// ?)
  • chomping filenames from readdir (where would the newlines have come from?)
  • using @dir == "" rather than just @dir to detect whether an array is empty
  • what does the code do when you have a file or directory name with a '+' or '%' character in it?
  • re-opening your database for each file/directory

What's wrong with something like:

use File::Find; use Cwd; my $homedir = getcwd(); open DATABASE, ">>$homedir/listofiles" or die "can't open listofiles: + $!\n"; open DATABASE2, ">>$homedir/listodirs" or die "can't open listodirs: $ +!\n"; File::Find::find( sub { return if /^\.\.?$/; return unless /\s/; if ( -d $_ ) { print DATABASE2 "$File::Find::name\n"; } else { print DATABASE "$File::Find::name\n"; } ( my $newName = $File::Find::name ) =~ s/\s+/_/g; print STDERR "renaming $File::Find::name to $newName\n"; # rename($File::Find::name, $newName) or die "can't rename : $!\n"; }, $homedir ); close DATABASE; close DATABASE2;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://104640]
[erix]: I've been to Amsterdam before you were born
[LanX]: 1899?
[chacham]: Just paint the white house black again.
dbander snorts
LanX Gesundheit! :)
talexb wonders about dividing developers in those born before the Unix timestamp of zero .. and after. Spoiler: I'm before.
chacham remebers I am a mad scientist
[stevieb]: talexb I'm after by a few years, but we can still be friends because you live in my hometown ;)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2017-08-18 13:24 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (302 votes). Check out past polls.