Re: getting a number out of a string....
- From: cdevers@xxxxxxxxx (Chris Devers)
- Date: Wed, 28 Dec 2005 20:17:34 -0500 (EST)
On Wed, 28 Dec 2005, David Gilden wrote:
> How does one just get the number part out of a string?
>
> The script below just prints 1.
Right. All it's doing is reporting a successful, true, match.
You need to fix where the parentheses are being used:
> foreach $str (@str) {
> $num = ($str =~ /\d+/);
> print "$str : $num\n";
> }
foreach (@str) {
( $num = $_ ) =~ /\d+/;
print "$_ : $num\n";
}
That should work better, and also avoids the confusing and unnecessary
$str temporary scalar that looks too much like the $str[] array. Also,
it's usefully indented, because Readability Matters.
--
Chris Devers
DO NOT LEAVE IT IS NOT REAL
.
- Follow-Ups:
- Re: getting a number out of a string....
- From: David Gilden
- Re: getting a number out of a string....
- From: Paul Lalli
- Re: getting a number out of a string....
- References:
- getting a number out of a string....
- From: David Gilden
- getting a number out of a string....
- Prev by Date: getting a number out of a string....
- Next by Date: Re: why a.pl is faster than b.pl
- Previous by thread: getting a number out of a string....
- Next by thread: Re: getting a number out of a string....
- Index(es):
Relevant Pages
|