[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] Bash Script Help



Almut Behrens wrote:

I assume I can make the first subexpression match zero or one time. In that situation if the first subexpression doesn't match does $1=null?

...exactly (though it's 'undef', not null, strictly speaking).  And
the nice thing is that Perl doesn't segfault or throw fatal exceptions
in such cases...  it just works as expected.  If used in a numeric
context, an undefined value will just evaluate to 0, which is typically
what you want.

So, the above s/// statement simply has to be modified as follows

 s/^((\d+):)?(\d+):([\d.]+)/sprintf "%.3f", $2*60**2 + $3*60 + $4/e

as you may have figured out yourself in the meantime.
yep I got it working just like this (w/o the '/sprintf "%.3f"' which I will add to ensure the precisions is explicit). I like the way it works; thanks for the tip. When I have free time later this summer I am going to learn some more about perl!



Reply to: