I am working on a program that take user input for two file names. Unfortunately, the program can easily break if the user does not follow the specified format of the input.
And here is one more way you could do it with regex (if you are reading the input from STDIN
):
# read a line from STDIN
my $filenames = ;
# parse the line with a regex or die with an error message
my ($qseq_filename, $barcode) = $filenames =~ /^\s*(\S.*?)\s*,\s*(\S.*?)\s*$/
or die "invalid input '$filenames'";