Perl script that stores all top level directories and files in array -
Perl script that stores all top level directories and files in array -
i making complicated believe. need script stores top level directories , files (in current working directory) array.
this have:
#!/usr/bin/perl utilize strict; utilize warnings; $dir = 'c:\tmp'; @names = (); opendir(dir, $dir) or die $!; while (my $file = readdir(dir)) { next if ($file =~ m/^\./); $file = "$file"." "; # print "$file"; @names = split( /\s+/,$file); foreach $slot (@names) { $slot = "$slot"." "; } print @names; } closedir(dir); exit 0; while works, know sloppy , overly complicating can't think of off top of head create easier. trying avoid using perl modules other basic (file::find ok, cnet modules aren't). question is, how can simplify this? thanks
this might want,
my @names = grep !/^[.]{1,2}$/, readdir(dir); your loop can reduced to
while (my $file = readdir(dir)) { next if $file =~ /^\./; $file =~ s/\s+/ /g; $file .= " "; print $file; } if makes sense?
perl
Comments
Post a Comment