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.


Comment on Re^2: No questions. Just a "thank you for named captures" !!
Select or Download Code
Re^3: No questions. Just a "thank you for named captures" !!
by jdporter (Canon) 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.