Re: getting a number out of a string....



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.
>
>
.



Relevant Pages

  • Re: getting a number out of a string....
    ... > How does one just get the number part out of a string? ... > The script below just prints 1. ... $str temporary scalar that looks too much like the $strarray. ...
    (perl.beginners)
  • Re: [PHP] Can i take the variable name in a function?
    ... // outputs 'This is a string, ... passed parameter which is $str. ... Obviously a well-structured application will keep the name consistent ... But, still, sooner or later, either in the script or the guts of PHP, ...
    (php.general)
  • Re: Valid e-mail script
    ... "Dave" wrote in message ... > Has anyone got a simple script to check a string is a valid e-mail ...
    (microsoft.public.scripting.jscript)
  • Re: ISAM error when trying to create tablelink
    ... Dim tDef As DAO.TableDef ... Doug Steele, Microsoft Access MVP ... Dim str As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: Using the Dictionary object
    ... Private Sub LV_ItemCheck ... Dim Str As String ... MyNext = MyNext - 1 ...
    (microsoft.public.excel.programming)