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

(bbq) RE: Re: Another flatfile thingy

by BBQ (Curate)
on Aug 04, 2000 at 17:47 UTC ( [id://26189]=note: print w/replies, xml ) Need Help??


in reply to Re: Another flatfile thingy
in thread Another flatfile thingy

Huh like $_, you REALLY like statement modifiers, don't you? :) Anyway, yeah that looks like lots of fun. I would never ship it out as production code, but still very fun! My favorite line from the above is:
s/^\s+|\s+$//g for @headers;
Waaaaaay cool! :)

Updated:
On a side note, I got a message from merlyn in the chatterbox pointing out that s/// for, has a great perfomance penalty despite its cool look. Then again, I believe that perlmonkey's idea was to make something funky as well and not be too worried about perfomance issues. Hey, we're all just tossing ideas here, right? Still, merlyn has a very good point that should be noted.

#!/home/bbq/bin/perl
# Trust no1!

Replies are listed 'Best First'.
RE: (bbq) RE: Re: Another flatfile thingy
by perlmonkey (Hermit) on Aug 04, 2000 at 20:44 UTC
    Hmm, did merlyn happen to mention a better construct, the s/// for ... it is something we put into production. I guess an alternative would be  map { s/^\s+|\s+$//g } @headers But I doubt it would be significantly better. I guess I will have to benchmark.

    Thanks!
      Nope, he just made a note of it. (Better than running with scissors though) :)

      I'd like to see the results of whatever you come up with in place of s/// for. (either that or I have to RTFM and learn once and for all how to use benchmark;)

      #!/home/bbq/bin/perl
      # Trust no1!
        Doing it in two steps is more efficient. From perlfaq4:
        It is much better faster to do this in two steps: $string =~ s/^\s+//; $string =~ s/\s+$//; Or more nicely written as: for ($string) { s/^\s+//; s/\s+$//; }
        Here's a benchmark:
        use Benchmark; timethese(500_000, { one => sub { my $foo = " perl monks "; $foo =~ s/^\s+|\s+$//g; }, two => sub { my $foo = " perl monks "; for ($foo) { s/^\s+//; s/\s+$//; } }, });
        And here are the results:
        Benchmark: timing 500000 iterations of one, two... one: 11 secs (11.75 usr 0.00 sys = 11.75 cpu) two: 8 secs ( 7.57 usr 0.00 sys = 7.57 cpu)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-18 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found