Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: variable list assignment

by mephit (Scribe)
on Aug 03, 2002 at 19:15 UTC ( [id://187374]=note: print w/replies, xml ) Need Help??


in reply to variable list assignment

I thought of something that *should* work, but I just can't come up with the code. Push a reference to each variable you want to assign to ($records[n]->{bytes}) onto an array and use that as the left hand side. Here's my code and its output:
my $num = 4; my @records = ( { bytes => 'foo0'}, { bytes => 'foo1'}, { bytes => 'foo2'}, { bytes => 'foo3'}, ); my @results; for (1 .. $num) { push (@results, [ $records[$_]->{bytes} ]); } @results = get_bytes($num); print Dumper (\@records); sub get_bytes { my $num = shift; my @ret; push (@ret, $_) for 1 .. $num; return @ret; } -------------- $VAR1 = [ { 'bytes' => 'foo0' }, { 'bytes' => 'foo1' }, { 'bytes' => 'foo2' }, { 'bytes' => 'foo3' }, {} ];
Notice the extra anonymous hash tacked onto the end of the (otherwise unchanged) @records array after calling get_bytes() Hmm, something tells me I would need to dereference each element in @results before calling the sub, but I'm stuck. Anybody have any ideas, or is my thinking just Not Good in this case?

--

There are 10 kinds of people -- those that understand binary, and those that don't.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-24 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found