Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Localizing hash keys in an AoH

by kennethk (Abbot)
on Mar 15, 2013 at 22:49 UTC ( #1023789=note: print w/replies, xml ) Need Help??


in reply to Re: Localizing hash keys in an AoH
in thread Localizing hash keys in an AoH

Very nice. I think this one would give my coworkers tremendous pause, but this will work in the general case, whereas NetWallah's solution fails if we have some more grotesque AoHoAoAoH thing going on.

Update: And it actually gives you tremendous control over localization scope, since you can stash the guard at whatever level you want. Nice.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^3: Localizing hash keys in an AoH
by tobyink (Abbot) on Mar 15, 2013 at 22:58 UTC

    It could be made more readable. Defining entire packages within a sub is a trick I'm fond of, but I'm aware it's not everybody's cup of tea.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re^3: Localizing hash keys in an AoH
by tobyink (Abbot) on Mar 17, 2013 at 00:32 UTC

    Indeed, but you don't really need to wait for the guard to go out of scope. It's just a blessed object, so you can call $guard->DESTROY manually any time you like.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023789]
help
Chatterbox?
[marto]: so I have to work Saturday, which is good and bad. Bad in the sense that I have to be hear early :( Good in that I am here only as support for another client project, so I get to spend the day working on my personal 'ToDo' list, without the kids :P
[Corion]: marto: Ooof - but yes, being there as only second level support or third level support is good and if you have enough things that you can work on, it won't be a wasted (if paid) day

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-02-28 10:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (399 votes). Check out past polls.