Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Is there any difference between prototype % and @ ?

by LanX (Canon)
on Feb 22, 2013 at 20:52 UTC ( #1020226=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Is there any difference between prototype % and @ ?
in thread Is there any difference between prototype % and @ ?

not in this case, cause I want to have it as fast and memory saving as possible.

thats why I'm splicing... though using indexes $_[$i] should be even faster...

just check the post I linked in the OP

Cheers Rolf


Comment on Re^4: Is there any difference between prototype % and @ ?
Download Code
Re^5: Is there any difference between prototype % and @ ?
by BrowserUk (Pope) on Feb 22, 2013 at 21:57 UTC
    not in this case, cause I want to have it as fast and memory saving as possible.

    Then why create a list from the hash in the first place?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      > Then why create a list from the hash in the first place?

      It's meant to be compatible with the standard interface!

      You might remember that map, sort and grep can be chained and they always accept and return lists...

      Cheers Rolf

        You might remember that map, sort and grep can be chained and they always accept and return lists...

        Hm. Passing a listified hash (mixed keys and values in random order) to any of those constructs is a completely pointless exercise.

        That is after all, why you are having to define an hgrep yourself.

        Better methinks to pass hgrep and hmap a reference to the hash, call the callback with pairs, and have them return a list.

        At least then they serve a purpose:

        #! perl -slw use strict; use Data::Dump qw[ pp ]; sub hgrep (&\%) { my( $code, $href ) = @_; map{ local @_; $code->( @_ = each %$href ) ? @_ : () } 1 .. keys %$href; } sub hmap (&\%) { my( $code, $href ) = @_; map{ local @_; $code->( @_ = each %$href ) } 1 .. keys %$href; } my %h = 'a'..'z'; print join ' ', hgrep{ $_[0] =~ /[a-m]/ } %h; print join ' ', hmap{ "$_[0] => $_[1]" } %h; my %orig = ( cat => 22, dog => 23, category => 66, catalyst => 77, cataclysm => 88, dogma => 89, dogstar => 92, ); my %h2 = hgrep{ $_[0] =~ /^cat/ } %orig; pp\%h2; __END__ C:\test>hfp e f a b m n c d k l g h i j w => x e => f a => b m => n s => t y => z u => v c => d k => l q => r +g => h i => j o => p { cat => 22, cataclysm => 88, catalyst => 77, category => 66 }

        hsort is left as an exercise.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-11-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls