http://www.perlmonks.org?node_id=1025057


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

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.

Replies are listed 'Best First'.
Re^4: ChainMap of Hashes on CPAN?
by LanX (Saint) on Mar 23, 2013 at 18:42 UTC
    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.
        ties are slow so no problem using a custom class.

        And you only implemented the lookup.

        I don't think it's worth making this core like they did for Py3, but having a well documented module on CPAN seems more efficient than writing, documenting and testing own code.

        I'm a big fan of lazy data structures and having such a tool in the box always opens the path to new uses cases.

        At least this way seems appropriate if one of the chained hashes is itself a tied structure.

        Cheers Rolf

        ( addicted to the Perl Programming Language)

Re^4: ChainMap of Hashes on CPAN?
by McA (Priest) on Mar 23, 2013 at 18:38 UTC

    I there a typo?

    McA