Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: (cLive ;-)(Golf) Analyzing Time From tcpdump Output

by chipmunk (Parson)
on Feb 05, 2002 at 03:43 UTC ( #143346=note: print w/replies, xml ) Need Help??


in reply to (cLive ;-)(Golf) Analyzing Time From tcpdump Output
in thread (Golf) Analyzing Time From tcpdump Output

I'm afraid your solution has a bug; the greedy matching of .* means that $2 only contains one of the digits before the decimal point, rather than both. Here's another way to match: perl -lp0e'/([\d.]{9}).*([\d.]{9})/s;$_=$2-$1'
Using -l is shorter than using $:, and avoids outputting a spurious '-' after the newline. :)

Replies are listed 'Best First'.
(cLive ;-)(Golf) Analyzing Time From tcpdump Output
by cLive ;-) (Prior) on Feb 05, 2002 at 07:45 UTC
    Are you sure? Try running it... :)

    The \d+ is greedy too...

    cLive ;-)

      Yes, I am sure. I did run it, and it output the wrong answer:
      -49.994325 -
      It doesn't matter that \d+ is greedy, because .* is greedy and gets to go first. The .* only backtracks far enough to allow the \d+ to match. \d+ can match a single digit, so .* only gives up a single digit. But to get the correct answer, \d+ has to match two digits before the decimal point, not one.

      On the other hand, it's okay if $2 only contains one digit before the decimal point, if $1 also contains a single digit before the decimal point: perl -lp0e'/(\d\.\d+).*(\d\.\d+)/s;$_=$2-$1'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://143346]
help
Chatterbox?
[Corion]: marto: Yeah, even though I didn't write any code :)
[Corion]: But at least I have a plan of action to move the site to https, played some (free!) VR games with friends and watched the plans for the next German Perl workshop progress ;)
[Corion]: AltSpace VR is amazingly good - highly polished and with some of the games you get for free what you'd pay EUR 20 or EUR 40 otherwise
[Corion]: But maybe it's also due to that I play with friends, which makes a game more enjoyable anyway ;)
[Corion]: Oh - I released a new version of some module, thanks to a pull request. But I don't consider "update Makefile.PL" and "update author tests" as "writing code" ;-D

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2017-08-21 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (319 votes). Check out past polls.

    Notices?