http://qs321.pair.com?node_id=1176718


in reply to Grab input from the user and Open the file

In addition to the excellent replies above I would like to mention file tests. While it is fine to attempt to open the file and then print out any errors, you can also test the file before you attempt to open it. If the file doesn't exist you could prompt the user to resubmit in case of a typo.

use warnings; use strict; my $directory = '/home/psimo/it441/challenge/logs'; + print "Please enter the file name: "; my $theFile = <STDIN>; chomp ($theFile); my $path = "$directory/$theFile"; if( ! -f $path ) { print "$path isn't a file.\n"; } else { print "$path is a file.\n"; } if( -T $path ) { print "$path is a text file.\n"; } else { print "$path is not a text file.\n"; }