Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: No questions. Just a "thank you for named captures" !!

by perl514 (Pilgrim)
on Feb 06, 2013 at 17:44 UTC ( [id://1017479]=note: print w/replies, xml ) Need Help??


in reply to Re: No questions. Just a "thank you for named captures" !!
in thread No questions. Just a "thank you for named captures" !!

Hi,

I am not entirely sure about %+ being slow. I tried running the script with numbered captures like $1 and $2 and then with named captures and quite frankly didnt notice much difference. May be using named captures makes some script/program run slightly slower, but I am not the kinds who would really worry about fractional speed.

Speaking of speed, I have tried other scripting languages and as of now, perl is atleast twice as fast. I tried parsing an XML File in Perl and Python and Ruby, and Perl seems to do it much faster. Not dissing Python/Ruby here, just stating what I saw.

As for "borrowing" stuff from other languages, I think it's about time that other languages give back something to Perl. :D

Perlpetually Indebted To PerlMonks

use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";
http://dwimperl.com/windows.html is a boon for Windows.

Replies are listed 'Best First'.
Re^3: No questions. Just a "thank you for named captures" !!
by jdporter (Chancellor) on Feb 07, 2013 at 02:52 UTC
    I think it's about time that other languages give back something to Perl. :D

    Smiley noted; but just so we're all clear, Perl has already borrowed tons of features from other languages.
    In some sense, it was originally invented as a synthesis of certain other languages.
    This is even stated in the original Perl man page, which is now entitled simply "perl":

    Perl combines (in the author's opinion, anyway) some of the best features of C, sed, awk, and sh, so people familiar with those languages should have little difficulty with it. (Language historians will also note some vestiges of csh, Pascal, and even BASIC-PLUS.)
    Also see this clpm discussion from 1999, ancestry of perl features.

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
Re^3: No questions. Just a "thank you for named captures" !!
by sedusedan (Monk) on Feb 07, 2013 at 16:50 UTC

    $ perl -MBench -e'$s = "a b"; /(\w+) (\w+)/; bench sub {$a=$1; $b=$2}, + -1' 3666664 calls (3339959/s), 1.098s (0.0003ms/call) $ perl -MBench -e'$s = "a b"; /(?<a>\w+) (?<a>\w+)/; bench sub {$a=$+{ +a}; $b=$+{b}}, -1' 636364 calls (560973/s), 1.134s (0.0018ms/call) $ perl -MBench -e'$s = "a b"; /(?<a>\w+) (?<a>\w+)/; %h=(a=>$+{a}, b=> +$+{b}); bench sub {$a=$h{a}; $b=$h{b}}, -1' 3333331 calls (3102372/s), 1.074s (0.0003ms/call)

    Accessing %+ elements is slower due to some tie magic. In general, yeah, you don't need to worry about it. But I managed to make Org::Parser and Text::sprintfn around twice as fast by avoiding named capture or copying %+ first to a temporary hash instead of accessing invididual %+ elements repeatedly.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-19 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found