in reply to How to read files in a directory, directory path to be given through CMD
or, if I wrote it,@files = <>; chomp @files; # Since there are trailing newlines foreach $file (@files) { if (-f $file) { print "This is a file: " . $file."\n"; } if (-d $file) { print "\n\nThis is a directory: " . $file."\n"; } }
What materials are you using to learn Perl? There are a number of great resources, including some free ones. For thorough coverage of available learning resources, see http://learn.perl.org.use strict; use warnings; my @files = <>; chomp @files; foreach my $file (@files) { if (-f $file) { print "This is a file: $file\n"; } if (-d $file) { print "\n\nThis is a directory: $file\n"; } }
Update: Corrected omitted chomp.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to read files in a directory, directory path to be given through CMD
by ckj (Chaplain) on Jun 11, 2012 at 19:12 UTC | |
by kennethk (Abbot) on Jun 11, 2012 at 19:23 UTC | |
by BrowserUk (Patriarch) on Jun 11, 2012 at 20:10 UTC |