Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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;

In reply to Re: Re: Re: opendir and directories that have spaces in them by bikeNomad
in thread opendir and directories that have spaces in them by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-18 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found