Re: getting a number out of a string....
- From: toddrw69@xxxxxxxxxx (Todd W)
- Date: Wed, 28 Dec 2005 20:31:09 -0500
"David Gilden" <dowda@xxxxxxxxxxxxxxxxxx> wrote in message
news:r02010500-1039-0B6C98E5780611DA9ADB0003935B6868@[192.168.0.100]...
> 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.
.
- References:
- getting a number out of a string....
- From: David Gilden
- 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 number out of a string....
- 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
|