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.