how to include single quotes from user input in perl -
the user going enter input string such tom's toy. perl script complains saying "unmatched '."
this code.
my $commandline=""; while (@argv) { $_ = shift @argv; {$commandline .= $_ . ' ';} } print " running $commandline\n"; system ($commandline); now if user input tom's toy. want print tom's toy. perl complains "unmatched '.". if dont user quote works fine. (for eg: tom toy good) how fix issue.
any appreciated. in advance
if switch things around little use system $cmd, @args version of function, no shell invoked, no escaping necessary.
my $cmd = shift @argv; @args = @argv; print " running $cmd\n"; system $cmd, @args; i tested ./test.pl echo tom\'s toy , gives expected output:
running echo tom's toy
Comments
Post a Comment