Re: getting a number out of a string....
- From: dowda@xxxxxxxxxxxxxxxxxx (David Gilden)
- Date: Thu, 29 Dec 2005 10:13:42 -0600
Chris,
Thanks and Happy New Year.
Dave
(kora musician / audiophile / webmaster @ www.coraconnection.com / Ft. Worth, TX, USA)
> > 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.
>
>
.
- References:
- Re: getting a number out of a string....
- From: Chris Devers
- Re: getting a number out of a string....
- Prev by Date: Re: why a.pl is faster than b.pl
- Next by Date: Re: getting a time diff from strings
- Previous by thread: Re: getting a number out of a string....
- Next by thread: Re: getting a number out of a string....
- Index(es):
Relevant Pages
|
|