in reply to STDIN help for a new Perl coder
Welcome here and to Perl.
If you read User input like that, you must know, that the linebreak will also be stored in your variable. So you must remove it; see chomp for details.
chomp( my $dir = <STDIN> );
Each statement should be completed with a ';', your chdir misses one.
You should check if chdir was successful and do something if it wasn't ($! contains the system's error message).
chdir( $dir ) or die "$dir: $!\n";
If you already changed into $dir, you must not specify it again in the glob pattern.
As you are using strict, you need to declare each new variable. You did it right with $dir, but not with @files.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: STDIN help for a new Perl coder
by perlJourney (Initiate) on Jul 15, 2009 at 18:05 UTC |