perl get partial string of a string

Hi All,

I have:

$d = "12.02222222222";
$d =~ s/(.*).(.*)/$1/e;

The output should be just 12.
Please guide me my expression wrong.

Thanks

$ 
$ perl -le '$d = "12.02222222222"; $output=sprintf("%d",$d); print $output'
12
$ 

tyler_durden

Change

$d =~ s/(.*).(.*)/$1/e;

to

$d =~ s/(.*)\.(.*)/$1/e;

Thanks tyler, tyler. It works :wink:

If i have a string
$val=14480 # This is seconds.

How would i make it into 040102, hhmmss, how should i use regular express to do :confused:.

Thanks

Regex can do a lot, but not that (and never were intended to [unless someone wants to prove me wrong])

perl -e '$val=14480; $hms=sprintf("%02d%02d%02d",int($val/3600),int($val%3600/60),int($val%60)); print $hms,"\n";'
040120

Thanks :eek: works.:o

---------- Post updated at 02:11 AM ---------- Previous update was at 02:08 AM ----------

Below is the finally code, hope this is the most simple method.
i have two date, i want to get the duration in to hhmmss format. Below is the working code.

$a = localtime(UnixDate(ParseDate("20090823 08:03:35"),"%s"));
$b = localtime(UnixDate(ParseDate("20090823 12:04:55"),"%s"));
$c = str2time($b)-str2time($a);
$hms=sprintf("%02d%02d%02d",int($c/3600),int($c%3600/60),int($c%60));
print $hms;