Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by LanX (Chancellor)
on Feb 24, 2013 at 03:34 UTC ( #1020370=note: print w/replies, xml ) Need Help??


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

> And so far; neither you nor I have come up with a use case.

trivial example

%salary=( boss => 1_000, secretary => 300, admin => 600, janitor => 150, ); print map {"$_ earns $salary{$_} \n" } sort { $salary{$a} <=> $salary{$b} } grep { $salary{$_} > 500 } keys %salary;

translating it to hmap, hsort and hgrep is left as an excercise.

Cheers Rolf

Replies are listed 'Best First'.
Re^15: Is there any difference between prototype % and @ ?
by BrowserUk (Pope) on Feb 24, 2013 at 08:37 UTC

    sub hpairs (\%) { my $href = shift; map[ each %$href ], 1 .. keys %$href; } my %salary = ( boss => 1_000, secretary => 300, admin => 600, janitor => 150, ); print for map { "$_->[0] earns $_->[1]" } sort { $a->[1] <=> $b->[1] } grep { $_->[1] > 500 } hpairs %salary; __END__ admin earns 600 boss earns 1000

    Or prettier:

    sub hpairs (\%) { use enum 'KEY', 'VAL'; my $href = shift; map[ each %$href ], 1 .. keys %$href; } my %salary = ( boss => 1_000, secretary => 300, admin => 600, janitor => 150, ); print for map { "$_->[KEY] earns $_->[VAL]" } sort { $a->[VAL] <=> $b->[VAL] } grep { $_->[VAL] > 500 } hpairs %salary;

    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.
      nice, but

      1. doesn't even try to use the hmap or hgrep you defended for so long
      2. you needed to introduce a completely new function hpairs
      3. still needs a unhpairs to flatten LoA before assigning after chain to a new hash
      4. my hmap could already be used instead of your hpairs (and unhpairs) in this approach ...

      Let's count, you're going to introduce 5 new functions where I only need 3 to cover all discussed cases...

      You really hate symmetry, don't you?

      Cheers Rolf

        1. doesn't even try to use the hmap or hgrep you defended so long

          I made no attempt to "defend". There is nothing to "defend".

          I offered an alternative, With reasoning. (I'm not forcing anyone to agree; nor use my ideas.)

        2. you needed to introduce completely new hpairs

          I use (or construct) the right tool for the job.

        3. still needs a unhpairs to flatten LoA before assigning to a new hash after chain

          Nothing new required, map serves the purpose perfectly.

        4. I could already use my hmap in your solution, so no need to create hpairs

          Look as hard as I might; I can't find your definition of hmap?

        5. you really hate symmetry, don't you?

          Nope! I "hate" very little. (And is that less "personal" that my recognising your ability?)

          But I do not seek to artificially impose symmetry where it does not naturally belong.


        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://1020370]
help
Chatterbox?
[Marshall]: stevieb wish you well with water problems, my water was off all day Monday for repairs. Any more progress on .exe info problem?.
[stevieb]: Marshall: no. I commented on the thread yesterday. Visual Studio updates the tags ok, but corrupts the exe
[stevieb]: I advised the OP that a possible workaround would be to add a version function/flag that displays the required copyright/license info instead
[Marshall]: Darn! I'll look at the thread. Must not be updatinga byte count somewhere. The .exe format is a complex critter.
[stevieb]: that way, it's still "hard coded" into the exe at least, despite not being visible via Properties
[Marshall]: I also looked into PerlApp from Active State, but they don't sell their Dev Kit independent of a very expensive ($1,200) per year license anymore.
[Corion]: I would assume that the PE format hasn't changed that much since the days of yore, but it seems that I would be wrong in that assumption
[Marshall]: When I bought my copy 15+ years ago, it was just a couple hundred bucks.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2016-12-08 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (144 votes). Check out past polls.