in reply to How to compare User Input to a file Name
Rather than searching the list of files, you could just check if the file exists. This approach would eliminate a lot of testing and guessing.
#!/usr/bin/perl -w use strict; my $path = '/Users/johnsmith/data'; my $fname; { print "Please enter a filename: "; chomp($fname = <STDIN>); last if -f "$path/$fname"; print "File does not exist!\n"; redo; } print "I have found '$fname' in '$path'.\n";
Note: Just in case you aren't trying to play guessing games with the user, you might want to consider displaying the list of available filenames. Reading up on globbing with the '<*.c>' operator or the glob operator itself should prove useful for that.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to compare User Input to a file Name
by rqatar2003 (Initiate) on Sep 23, 2008 at 16:59 UTC |