Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Thanks for the response. The information flow seems off from my needs based upon how I'm looking at your code, but somehow it shook loose the idea of performing the localization on the full hash, and not trying to compound it with setting keys. That gave me this:
sub localised { package localised; use Scalar::Util 'reftype'; my $ref = shift; my $reftype = reftype $ref or die "$ref is not a reference"; my @old = $reftype eq 'SCALAR' ? $$ref : $reftype eq 'ARRAY' ? @$ref : $reftype eq 'HASH' ? %$ref : die sprintf "Unsupported reftype %s", reftype $ref; return bless [$ref, @old]; sub DESTROY { my ($ref, @old) = @{+shift}; my $reftype = reftype $ref; $reftype eq 'SCALAR' ? ($$ref) : $reftype eq 'ARRAY' ? @$ref : %$ref = @old; } }

I feel like there may be a reasonable way to roll optional assignment in there simultaneously, but cleanly and across data types is escaping me.

I've never been a big user of tie, so thank you for giving something to chew on. I can vaguely see how a full understanding of how to implement this in tie combined with guards would result in a really swanky solution, but my brain is too stupid today to implement that one.


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


In reply to Re^2: Localizing hash keys in an AoH, continued by kennethk
in thread Localizing hash keys in an AoH, continued by kennethk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found