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

2005-12-29 Thread David Gilden
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.
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




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

2005-12-28 Thread Todd W

"David Gilden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Greetings,
>
> How does one just get the number part out of a string?
>
> The script below just prints 1.
>
> #!/usr/bin/perl
>
> @str =
('Gambia001.tiff','Gambia0021.tiff','Gambia031.tiff','Gambia035.tiff') ;
>
> foreach $str (@str) {
> $num = ($str =~ /\d+/);
> print  "$str : $num\n";
> }

You migght try this:

use warnings;
use strict;

my @str = qw(Gambia001.tiff Gambia0021.tiff Gambia031.tiff Gambia035.tiff);

foreach my $str (@str) {
  my($num) = $str =~ /(\d+)/;
  print  "$str : $num\n";
}

output:

$ perl extrt.pm
Gambia001.tiff : 001
Gambia0021.tiff : 0021
Gambia031.tiff : 031
Gambia035.tiff : 035

> Thanks!

You bet!

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




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

2005-12-28 Thread Chris Devers
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]
 




getting a number out of a string....

2005-12-28 Thread David Gilden
Greetings,

How does one just get the number part out of a string?

The script below just prints 1.

#!/usr/bin/perl 

@str = ('Gambia001.tiff','Gambia0021.tiff','Gambia031.tiff','Gambia035.tiff') ;

foreach $str (@str) {
$num = ($str =~ /\d+/);
print  "$str : $num\n";
}


Thanks!
Dave Gilden
(kora musician / audiophile / webmaster @ www.coraconnection.com  / Ft. Worth, 
TX, USA)

Endorsing Artist for the Moog Music:


==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments & More!
    
==

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]