WoodyWeaver has asked for the wisdom of the Perl Monks concerning the following question:
I'm parsing time from a last output. I got an unexpected input, so getting an unexpected output shouldn't be surprising, but for the life of me I can't figure out what perl is doing.
subroutine is
I was processing a linesub minutes { my $time = shift; print "minutes handed $time " if $DEBUG_MINUTES; if ( $time =~ /(\d+):(\d+)/ ) { print "Interpreted as $1 hours $2 mins\n" if $DEBUG_MINUTES; return 60 * $1 + $2; } elsif (/(\d+)+(\d+):(\d+)/) { print "Interpreted as $1 days, $2 hours, $3 minutes\n" if $DEBUG_M +INUTES; return ( 24 * $1 + $2 ) * 60 + $3; } else { warn "I don't understand time $time\n"; return $time; } }
and I getarcherh Thu Jun 22 10:25 - down (-6+-1 +2:-52)
How does \d+ do this?minutes handed -6+-12:-52 Interpreted as 1 days, 0 hours, 25 minutes
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: unexpected RE match
by Anonymous Monk on Jul 05, 2017 at 23:01 UTC | |
by WoodyWeaver (Monk) on Jul 05, 2017 at 23:05 UTC | |
by Anonymous Monk on Jul 07, 2017 at 01:42 UTC | |
by Anonymous Monk on Jul 06, 2017 at 22:43 UTC |