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?
print "Enter name of directory (fully qualified path): ";
my $dir = <STDIN>;
@files = <$dir/*>;
foreach $file (@files)
print $file "\n";