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;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.