Hi All,
I would like to convert my below csh script to Perl.
Can any expert help ?
# To check for numeric input
set tested1 = `echo "$tested"| awk '/^[0-9]+$/'`;
# To remove un-neccessary zeros
set tested2 = `echo "$tested"|awk '{print $0+0}'`;
Hi All,
I would like to convert my below csh script to Perl.
Can any expert help ?
# To check for numeric input
set tested1 = `echo "$tested"| awk '/^[0-9]+$/'`;
# To remove un-neccessary zeros
set tested2 = `echo "$tested"|awk '{print $0+0}'`;
if ($tested=~/^(\d+)$/) { # Block will only be entered when it's only digits
$tested1 = $1; #Leading zeros are automagically removed.
}
Hi pludi,
Thks for your advice.
But what does $1 represent in Perl.
I only understand that $1 represent 1st field in AWK, is that the same for Perl ?
When using brackets in regular expressions you start a capturing group, meaning anything that matches the regex inside will also be made available outside the regex. These groups are captured to $1, $2, $3, ...
Another option might be to save those captures to an array using
@arr=$tested=~/(\d+)/g
but this usually isn't useful if you want to match the whole line.
Good follow-up reading: perldoc perlre