Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: selectall_hashref structure

by vitoco (Hermit)
on Dec 24, 2009 at 15:41 UTC ( [id://814250]=note: print w/replies, xml ) Need Help??


in reply to selectall_hashref structure

I'm not sure about what you want to do, but I hope this helps:

#!perl use strict; use warnings; use Data::Dumper; my $id = '1C8962EB'; myfunction($id, { max => 90, cval => 89 }); sub myfunction { my %p = %{$_[1]}; print Dumper(\%p); my %newp = map { $_ => { value => $p{$_}, key => $_, id => $_[0] } + } keys %p; print Dumper(\%newp); } __END__ $VAR1 = { 'max' => 90, 'cval' => 89 }; $VAR1 = { 'cval' => { 'value' => 89, 'id' => '1C8962EB', 'key' => 'cval' }, 'max' => { 'value' => 90, 'id' => '1C8962EB', 'key' => 'max' } };

Replies are listed 'Best First'.
Re^2: selectall_hashref structure
by 0xbeef (Hermit) on Dec 24, 2009 at 16:25 UTC
    Thanks it does help, I was just wondering if there was any way to avoid having to use map or another transformation at all.

    To clarify the original objective, it was to have a common hash structure between the function I mentioned and results from selectall_hashref.

    I was trying to find a way to manipulate the selectall_hashref to provide a resulting hash as described that can be used as $$hash{$id}{$key} = $value.

    Your code provides a valid solution albeit through a different approach - "modify the structure passed to the function to look like the result from the selectall hash", and should work just fine unless someone can come up with an even better solution.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-16 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found