Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: ChainMap of Hashes on CPAN?

by BrowserUk (Pope)
on Mar 23, 2013 at 18:34 UTC ( #1025057=note: print w/ replies, xml ) Need Help??


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.


Comment on Re^3: ChainMap of Hashes on CPAN?
Download Code
Re^4: ChainMap of Hashes on CPAN?
by McA (Curate) on Mar 23, 2013 at 18:38 UTC

    I there a typo?

    McA

Re^4: ChainMap of Hashes on CPAN?
by LanX (Canon) 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)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-08-23 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls