in reply to tied hash for data munging

Yes, I could iterate over the keys using ref or such, but I would rather want to say: %out = %h;

Immediate reaction: That's an awful lot of magical code to substitute for: %out = map{ ( $_ => ref( $h{$_} ? $h{$_}->() : $h{$_} ) } keys %h;

Maybe I'm missing something?


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.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re^2: tied hash for data munging
by shmem (Chancellor) on Jul 11, 2015 at 13:04 UTC
    Maybe I'm missing something?

    Hell yes - the YAGNI part of it, which is the code generation, and the variable binding (which can be used for closures in the generating sub):

    my $config = Config::Tiny->read($inifile); for my $key (keys %$config){ my $section = $config->{$key}; my $record; tie my %h, 'Sub::Hash', $gensub, $record; # $record bound %h = %{$section}; # transforms all INI file values # from this section into CODE refs my $result = getData( delete $h{SOURCE} ); for $record (values %$result) { write_csv( my %out = %h ); } }

    This replaces an awful lot of code - which, I admit, could also be hidden in subroutines.

    update:

    Well, not so much really. Of course the subroutine table could also be set up as

    %h = map { $_, $gensub->( $section->{$_} ) } keys %$section;

    But the point of the whole thing is to have all that encapsulated in a single tied hash, which is arguably not so great an a good idea.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'