The easiest way is to use the glob function to let Perl find the file for you:
#!/usr/bin/perl -w use strict; # this is just so that glob() whitespace handling is sane use File::Glob qw(bsd_glob); my $fname = "empty"; my @found_files; while (! @found_files){ print "Please enter Filename: "; chomp($fname = <STDIN>); @found_files = glob( "/Users/johnsmith/data/$fname*" ); if (@found_files != 1) { if (@found_files == 0) { print "File '/Users/johnsmith/data/$fname*' does not ex +ist.\n\n"; } else { print "There are multiple files matching '/Users/johnsm +ith/data/$fname*':\n"; print "$_\n" for @found_files; }; }; } print "I have found this '$found_files[0]' in your directory\n\n";
In reply to Re: How to compare User Input to a file Name
by Corion
in thread How to compare User Input to a file Name
by rqatar2003
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |