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




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


.



Relevant Pages

  • Re: Updating registry keys for Internet Explorer bombs-out
    ... It looks like the problem is the lack of quotes ... string values. ... > I have a script that I am updating Internet Explorer settings for the ... Prev by Date: ...
    (microsoft.public.scripting.vbscript)
  • Function to retrieve running script
    ... Is there a function that allows one to get the name of the same script ... running returned as a string? ... Harlin Seritt ... Prev by Date: ...
    (comp.lang.python)
  • How can I create a global variable?
    ... I have two vbScripts. ... String, so that ... I can read this variable in a other script - msgBox glVariable. ... Prev by Date: ...
    (microsoft.public.scripting.vbscript)
  • Re: Function to retrieve running script
    ... Harlin Seritt wrote: ... > Is there a function that allows one to get the name of the same script ... > running returned as a string? ... Prev by Date: ...
    (comp.lang.python)
  • "Type mismatch" error in JScript - newby question
    ... I'm trying to create a simple text file that will allow a string of text to ... The script firstly creates the text file, ... to then open that file for writing into it, I keep on getting a "type ... Prev by Date: ...
    (microsoft.public.scripting.jscript)