in reply to Re: what is the best way to seperate the digits and strings from variable ?
in thread what is the best way to seperate the digits and strings from variable ?
Please, test your code.
\d* will match 0 (ZERO) or more digits.
Thus, it will happily match an empty string at the beginning of a string like "abc123" and return a 0 length string. Try it.
The right expression to use in this case is \d+.
Moreover, a capturing regular expression should always be used with a test:
my $num; my $variable = "abc123"; if ( $variable =~ /(\d+)/) { $num = $1; }
In Section
Seekers of Perl Wisdom