Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: parsing question

by Wonko the sane (Deacon)
on May 28, 2003 at 13:49 UTC ( #261299=note: print w/replies, xml ) Need Help??

in reply to parsing question

I like kilinrax use of reverse, I have never seen that trick before.
Without knowing that I would have suggested a capturing regex,
sort of a modification of the greedy suggestion.

It benchmarks the fastest of the three.

#!/usr/local/bin/perl use strict; use Benchmark; my $string = "<<HTML>;nbsp dont_strip_me</HTML>> <xyzfdgfghgf> ;strip_ +me"; sub reversed { my $reverse = reverse(shift); $reverse =~ s| \w* ; \s* > |>|x; return scalar reverse $reverse; } sub greedy { my $line = shift; $line =~ s|^ (.*>) \s* ; \w* |$1|x; return $line; } sub capture { my $line = shift; return $line =~ /^(.+>)/; } print "Reversed: ", reversed($string), "\n"; print "Greedy: ", greedy($string), "\n"; print "Capture: ", capture($string), "\n"; timethese( -10,{ reversed => sub { reversed( $string ) }, greedy => sub { greedy( $string ) }, capture => sub { capture( $string ) }, } );
:!./ Reversed: <<HTML>;nbsp dont_strip_me</HTML>> <xyzfdgfghgf> Greedy: <<HTML>;nbsp dont_strip_me</HTML>> <xyzfdgfghgf> Capture: <<HTML>;nbsp dont_strip_me</HTML>> <xyzfdgfghgf> Benchmark: running capture, greedy, reversed, each for at least 10 CPU + seconds... capture: 10 wallclock secs (10.40 usr + 0.01 sys = 10.41 CPU) @ 53 +160.52/s (n=553401) greedy: 10 wallclock secs (10.52 usr + 0.00 sys = 10.52 CPU) @ 21 +887.07/s (n=230252) reversed: 11 wallclock secs (10.54 usr + 0.01 sys = 10.55 CPU) @ 36 +366.92/s (n=383671)


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://261299]
[Corion]: I just found out that in $current_top_prior ity_project , the part I am in is not even in the top three worries. That's somewhat bad, not because I'm happy with being a top worry but because that means that I don't even know how bad the rest ...
[Corion]: ... of the situation is :-)
[marto]: it's good to know that things can always get worse :P
[hippo]: Ignorance can be bliss
[Corion]: hippo: Yeah - I'll just avoid the project lead :)
[Corion]: marto: Yeah, it helps with the perspective :-D

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2017-07-26 08:13 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (385 votes). Check out past polls.