Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Localizing hash keys in an AoH

by Anonymous Monk
on Mar 15, 2013 at 19:38 UTC ( #1023764=note: print w/replies, xml ) Need Help??


in reply to Localizing hash keys in an AoH

String eval, naturally

I think maybe something could be cobbled together using Scope::Upper and/or Devel::Declare, maybe

Replies are listed 'Best First'.
Re^2: Localizing hash keys in an AoH
by kennethk (Abbot) on Mar 15, 2013 at 21:05 UTC
    So string eval works so long as the entire trailing code block is in the string, which gets pretty clunky for one scenario I'm dealing with. But it works, which is better than I've gotten on my own.
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @data = ( {unit => 'S', value => 50, }, {unit => 'T', value => 60, }, {unit => 'Q', value => 70, }, ); LOCAL_BLOCK: { my $cmd; $cmd .= "local \$data[$_]{unit} = 'S';\n" for 0 .. $#data; $cmd .= 'print Dumper \@data'; eval $cmd; } print Dumper \@data;

    I'll do some digging on the cited modules, to see if they work in my context.


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023764]
help
Chatterbox?
[LanX]: OH
[LanX]: you are talking about signatures?
[GotToBTru]: yes, it turns out I am
[LanX]: http://perldoc. perl.org/perlsub. html#Prototypes
[GotToBTru]: that page, strangely enough, never mentions that construct
[LanX]: ; is for optional prototypes
[LanX]: & is codeblock @ array
[GotToBTru]: okay, that is there in the text, not in literal use in any of the examples
[GotToBTru]: the text suggest it is redundant before @
[LanX]: propably ... I also notice new stuff

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2017-01-18 21:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (164 votes). Check out past polls.