"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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to