Wiggins d'Anconia wrote:
This example only matches when *all* of the possibles are supplied,
> which is explicitly what he stated he didn't have.
Thanks,
Sorry, careless reading. I'd thought he only wanted to extract certain values from a
full string. This should be a little more robust:
#!
R. Joseph Newton wrote:
dan wrote:
I have a string, which is to represent a length of time, say 3d4h45m12s
which can be variable, so you may end up with just 3m, or 5h2m, etc. What I
need to do, is to take this string, and split it up into $days, $hours,
$minutes etc, and then create that amoun
dan wrote:
> I have a string, which is to represent a length of time, say 3d4h45m12s
> which can be variable, so you may end up with just 3m, or 5h2m, etc. What I
> need to do, is to take this string, and split it up into $days, $hours,
> $minutes etc, and then create that amount of time in second
Oops!
$ perl -e '
@z = qw( 3d20m 5d2h 2h2s );
for $v (@z){
$v =~ s/d/*24*3600 +/;
$v =~ s/h/*3600 +/;
$v =~ s/m/*60 +/;
$v =~ s/s/ +/;
chop $v;
$k = eval $v;
print "$v = $k seconds";
print "\n";
}'
3*24*3600 +20*60 = 260400 seconds
5*24*3600 +2*3600 = 439200 seconds
2*3600 +2 = 7202 seconds
But
"John W. Krahn" wrote:
>
> Dan wrote:
> >
> > I have a string, which is to represent a length of time, say 3d4h45m12s
> > which can be variable, so you may end up with just 3m, or 5h2m, etc. What I
> > need to do, is to take this string, and split it up into $days, $hours,
> > $minutes etc, and th
Dan
> I have a string, which is to represent a length of time, say 3d4h45m12s
$ perl -e '
$v = "3d7h36m14s";
$v =~ s/d/*24*3600 +/;
$v =~ s/h/*3600 +/;
$v =~ s/m/*60 +/;
$v =~ s/s//;
$k = eval $v;
print "$v = $k seconds";'
3*24*3600 +7*3600 +36*60 +14 = 286574 seconds
And a question. Can the 4 $v
dan wrote:
> Hi again,
>
> Sorry for firing many questions at you tonight, this one's probably
> simple, but I've racked my brains and can't think of anything for
> this one.
>
> I have a string, which is to represent a length of time, say
> 3d4h45m12s which can be variable, so you may end up with
Dan wrote:
>
> Hi again,
Hello,
> Sorry for firing many questions at you tonight, this one's probably simple,
> but I've racked my brains and can't think of anything for this one.
>
> I have a string, which is to represent a length of time, say 3d4h45m12s
> which can be variable, so you may end
Dan,
Here's my solution. I'm not capturing the days, hours, minutes, seconds
as I go, but I'm sure you can see how to if it's really necessary.
#!/usr/bin/perl -w
use strict;
my @list=('3d4h45m12s', '3h', '5h2m');
foreach (@list) {
my $seconds=0;
my $string=$_;
while ($string=~s/(\