I’m a novice. Sorry. I’m trying to remove commas. Perl cgi.pm
I need to know how to write this param(‘item_price’ => ~ s/\,//g);
I can do this $item_price =~ s/\,//g; but would rather eliminate the conversion to variable.
What would be even better is if I can include removal of $. Can it be done? Thanks
I’m a novice. Sorry. I’m trying to remove commas. Perl cgi.pm I need to
Share
No. You can only apply a replace RegEx to an l-value (an expression that you can assign a value TO), since it needs to write back the changed string.
From
perldoc perlopfors///operator:A subroutine/method call is NOT an l-value.
There are 3 workarounds possible:
Assign results of the subroutine call to a variable, and run the RegEx on the variable.
It may be slightly longer code, but it’s clean, readable, and not bug prone. Best solution.
Upgrade to Perl 5.14 and use
/rRegEx modifier.[BAD IDEA!!!] If the param value is stored internally in CGI.pm, go into CGI object’s internal storage and apply the regex to the value stored in the object. You should almost NEVER do that!