perlJourney has asked for the wisdom of the Perl Monks concerning the following question:
I am hoping I can gain an insight to a problem I am having. I am new to Perl and I am trying to write a code snippet that will allow me to list the directory contents of a directory that is specified taking user input. What I am intending to do is take the user input, place it in a variable and then pass that variable along to chdir and such but it will not change the directory. If I hardcode the directory into the variable ($dir = /etc) then it works fine. This is what I have so far in terms of code... can someone please show me what would work?
<code>
#!/usr/bin/perl
use strict;
use warnings;
print "Enter name of directory (fully qualified path): ";
my $dir = <STDIN>;
chdir($dir)
@files = <$dir/*>;
foreach $file (@files)
{
print $file "\n";
}
<code>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: STDIN help for a new Perl coder
by ikegami (Patriarch) on Jul 15, 2009 at 16:51 UTC | |
by perlJourney (Initiate) on Jul 15, 2009 at 18:02 UTC | |
Re: STDIN help for a new Perl coder
by gwadej (Chaplain) on Jul 15, 2009 at 16:54 UTC | |
by perlJourney (Initiate) on Jul 15, 2009 at 18:03 UTC | |
Re: STDIN help for a new Perl coder
by kennethk (Abbot) on Jul 15, 2009 at 17:03 UTC | |
by perlJourney (Initiate) on Jul 15, 2009 at 18:13 UTC | |
by kennethk (Abbot) on Jul 16, 2009 at 14:07 UTC | |
Re: STDIN help for a new Perl coder
by linuxer (Curate) on Jul 15, 2009 at 16:59 UTC | |
by perlJourney (Initiate) on Jul 15, 2009 at 18:05 UTC |