Experts,
I need to develop a perl code to catch invalid user inputs. In my case, a backslash ("\") is considered invalid.
Here is my code:
Here is the output from a test run:
Could someone tell me how to fix this problem? Many thanks!
I need to develop a perl code to catch invalid user inputs. In my case, a backslash ("\") is considered invalid.
Here is my code:
Code:
my @invalidCharList = ('-', '\+', '\.', '/', '\\');
#my @invalidCharList = ('-', '\+', '\.', '/');
print "$0..testing..., @invalidCharList\n";
print "Enter something: ";
while(1)
{
my $input = <STDIN>;
chop($input);
print "\$input = $input\n";
my $ii = 0;
foreach my $c (@invalidCharList)
{
if($input =~ /$c/ && $Q::mode ne 'edit')
{
warn("catch!!! \$ii = $ii, \$input = $input, \$c = #$c#");
}
$ii++;
} # end of foreach my $c (@invalidCharList)
if($input eq "q")
{
print "exit...\n";
exit;
}
print "\nEnter something again: ";
}
Here is the output from a test run:
Code:
% ./catchBackSlash.pl
./catchBackSlash.pl..testing..., - \+ \. / \
Enter something: a
$input = a
[red]Trailing \ in regex m/\/ at ./catchBackSlash.pl line 17, <STDIN> line 1.[/red]
Could someone tell me how to fix this problem? Many thanks!