Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: ChainMap of Hashes on CPAN?

by LanX (Canon)
on Mar 23, 2013 at 16:54 UTC ( #1025046=note: print w/ replies, xml ) Need Help??


in reply to Re: ChainMap of Hashes on CPAN?
in thread ChainMap of Hashes on CPAN?

> I'm just wondering (but not dismissing) the use-case?

It's useful to avoid the overhead of concatenating very long hashes if you only need few lookups.

A "lazy" approach if you want.

There some use cases listed in the Py-docs and have a look into the talk for his justification (I deep-linked to 29m10s)

But actually I'm also suspicious about the frequency of such valid use cases, in those rare cases I would personally simply reimplement the get() function as a wrapper like I showed.

Now my intention was to show how easily a py-idiom can be adapted.

But this talk is quite interesting, it often goes into length to describe how to solve problems we do not have in the realm of the onion.

And this with a kind of "hurray" attitude which is somehow alien to me... ¹

Cheers Rolf

( addicted to the Perl Programming Language)

¹) but alas Europeans are bad in marketing! ;-)


Comment on Re^2: ChainMap of Hashes on CPAN?
Re^3: ChainMap of Hashes on CPAN?
by McA (Curate) on Mar 23, 2013 at 17:02 UTC

    I had to laugh and just wanted to ask what vidoes you are watching... ;-)

    I have to cite from Monty Python’s Life of Brian:

    Are there any women(*) here today?

    McA

    (*) pythonistas

      Actually our local perlmongers group is "racially mixed" and we like comparing and learning from different approaches.

      I raised a discussion about how easy the counting idioms are implemeted in Perl because undef ++ == 1 and autovivification and was wondering how JS, Ruby and Python and so on are trying to solve this.

      (Our Haskell guy couldn't stop complaining how dirty Perl's behavior is)

      Now try this in these languages

      $count{$_}++ for @names

      or

      DB<135> @name=qw/rachel raymond matthew roger betty melissa judith c +harlie/ DB<136> push @{ $group{length $_} } , $_ for @name DB<137> \%group => { 5 => ["roger", "betty"], 6 => ["rachel", "judith"], 7 => ["raymond", "matthew", "melissa", "charlie"], }

      This video was mailed to me with the remark "this is clean idiomatic Python" and the speaker talks for minutes about strategies to count and group.

      There is indeed MOOOOOORE than one way to do it in Python where Perl has one simply way.

      --> http://stackoverflow.com/questions/3496518/python-using-a-dictionary-to-count-the-items-in-a-list

      We are quite fast in criticizing the downsides of some Perl features, it's worth showing where Perl profits from those features.

      "Only an idiot learns from his errors, the smart guy learns from other's errors"
      (attributed to Otto von Bismarck)

      And not everything I learned in this video was a bad idea!

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        Hi Rolf,

        I do have my own Python journey behind me. There are many things which are not bad. Be sure, I'm not a Perl fanatic. :-)

        McA

Re^3: ChainMap of Hashes on CPAN?
by BrowserUk (Pope) on Mar 23, 2013 at 18:34 UTC
    It's useful to avoid the overhead of concatenating very long hashes if you only need few lookups.

    Then I think I'd use:

    my $thing; exists $_->{ $key } and $thing = $_->{ $key } for \(%hash1, %hash2, %h +ash3);

    and save constructing a whole (class of) objects for something so trivial.

    But, I don't ever remember having such a requirement; nor can I think of an actual use-case.


    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.

      I there a typo?

      McA

      Well your code has a logical flaw and a typo.

      And I already explained that I would probably do something similar.

      Cheers Rolf

      ( addicted to the Perl Programming Language)

      UPDATE:

      this works:

      exists $_->{ $key } and $thing = $_->{ $key },last for \(%H1, %H2);

        Well your code has a logical flaw and a typo.

        Obviously untested, but the point was that I cannot see the purpose for a subroutine, never mind a whole class for such a purpose.

        I've found this kind of thing very prevalent in Python (& ruby) code that I've converted in the past.

        You get a whole bunch of classes to implement some algorithm; but when you strip away the boiler place and make-work, you end up with one or two lines from each class actually doing useful work. (In Perl at least.)


        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://1025046]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2014-10-23 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls