in reply to STDIN help for a new Perl coder
chomp(my $dir = <STDIN>);
chdir($dir);
my @files = <$dir/*>; foreach my $file (@files)
print $file, "\n";
You also might want to read Markup in the Monastery since you haven't followed site protocol. Rather than using a glob, I'd also use opendir, readdir and closedir to protect yourself from typos and pathological file names.
#!/usr/bin/perl use strict; use warnings; print "Enter name of directory (fully qualified path): "; chomp(my $dir = <STDIN>); opendir my($dirhandle), $dir or die "No such directory: $dir"; my @files = readdir($dirhandle); closedir($dirhandle); foreach my $file (@files) { print $file, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: STDIN help for a new Perl coder
by perlJourney (Initiate) on Jul 15, 2009 at 18:13 UTC | |
by kennethk (Abbot) on Jul 16, 2009 at 14:07 UTC |