in reply to getting a number from a string
my $string = "Happy Joy 002245:Dubloons 002256:hats 034523:paper clips + 232344:pants 233394"; my @items = split /:/, $string; my $number; $number = $1 if $items[0] =~ m/(\d+)/; print $number, "\n";
Make sure not to use $number if a match didn't occur. Also, this method provides you with every item. I know you mentioned only wanting the first. If that's all you'll ever need, you can just do this:
$number = $1 if $string =~ m/(\d+):/; print $number, "\n";
Cheers!
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: getting a number from a string
by shaezi (Acolyte) on Jan 05, 2004 at 05:48 UTC |