> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf 
> Of Naresh
> Bajaj
> Sent: Wednesday, 22 March 2006 12:29 PM
> To: [email protected]
> Subject: Extracting numbers from a string
> 
> 
> Hello all,
> I have one string PT2H46M7.815S.
> It is in hours, minutes and seconds. I want to extract number between
> the alphabets and
> stored in seconds. How should I approach this problem.
> Right now I am using the split command which is not much elegant way.
> Crude method:
> extractinterval(PT7.815S)
> sub extractinterval{
>       my $interval =$_[0];
>       my @temp =split //,$interval;
>         my $output = $temp[2].$temp[3].$temp[4].$temp[5];
>       }
> Is there any other way of doing.
> Thanks,
> Naresh
> --
> Naresh Bajaj, Intern,
> Cardiac Rhythm Disease Management,
> Medtronic Inc.,
> 763-514-3799
> 

use strict;
use warnings;

my $time = "PT2H46M7.815S";
my ($h,$m,$s) = $time =~ m/PT(\d+)H(\d+)M(.*?)S/;
print "$h:$m:$s";

__END__

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to