Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

(jcwren) RE: regexp's

by jcwren (Prior)
on Oct 03, 2000 at 06:24 UTC ( #35040=note: print w/replies, xml ) Need Help??


in reply to regexp's

Or, in a few less lines...
#!/usr/local/bin/perl -w use strict; { my %hash = (); while (<DATA>) { my @items = split; $hash {pop @items} = shift @items; } print "key=$_, val=$hash{$_}\n" foreach sort keys (%hash); } __DATA__ 1 time 02:11:05 djw 5 time 04:20:03 bert 2 time 00:01:39 chris

[jcw@linux fs]$ perl q.pl key=bert, val=5 key=chris, val=2 key=djw, val=1 [jcw@linux fs]$


--Chris

e-mail jcwren

Replies are listed 'Best First'.
RE: (jcwren) RE: regexp's
by extremely (Priest) on Oct 04, 2000 at 02:17 UTC

    A benchmark vs. Ovid's regex. =) Tho you all knew split beats regex, here is the numbers.

    Benchmark: timing 50000 iterations of Ovid, jcwren...
          Ovid:  4 wallclock secs ( 3.32 usr +  0.00 sys =  3.32 CPU) @ 15060.24/s (
    n=50000)
        jcwren:  2 wallclock secs ( 2.63 usr +  0.00 sys =  2.63 CPU) @ 19011.41/s (
    n=50000)
              Rate   Ovid jcwren
    Ovid   15060/s     --   -21%
    jcwren 19011/s    26%     --

    --
    $you = new YOU;
    honk() if $you->love(perl)

RE: (jcwren) RE: regexp's
by princepawn (Parson) on Oct 03, 2000 at 18:03 UTC
    My

    GOD

    that is elegant. Too bad I can only ++ you one time on that one. This is one the most elegant things I have EVER seen, save for something merlyn did in Effective Perl programming:
    ($_ & ~$_) eq 0
    to determine if a scalar is a number (i may be slightly off on the actual expression)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://35040]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2020-11-25 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?