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

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to