This is a small little question:
How do you take the variables $1 to $100 (as matched through regexp) and put them into a hash, where the keys of the hash would be 1 to 100?
I've tried a few things, such as:
It seems like there should be an easy solution without having to resort to eval.
How do you take the variables $1 to $100 (as matched through regexp) and put them into a hash, where the keys of the hash would be 1 to 100?
I've tried a few things, such as:
Code:
for (my $i = 1; $i <= 100; $i++) {
# Tried this
$stars{$i} = \${$i};
# And this
$stars{$i} = ${$i};
# And this
$stars{$i} = \$i
# And none of them worked.
# This was the only solution I could find:
$stars{$i} = eval ('$' . $i);
}
It seems like there should be an easy solution without having to resort to eval.