in reply to Constructing Variable Arrayname
Dominus has said it much better than I can, in his series about using a variable to construct the name of a second variable. You almost never want to do that.
In your case, you are most likely better off in constructing an Array of Arrays ("AoA"):
# verbose: my @stats; # Initialize the 12 months: my $months = 12; for (0..$months-1) { $stats[$_] = []; # empty array at first }; my $month = 2; my $value = 300; push @{ $stats[ $month ] }, $value; my $nr = 2; print join ",", @{ $stats[ $nr ] };
You might also want to consider using a database like SQLite for your statistics, as you can then more easily aggregate not only by month but also by other criteria. In any case, go and read Dominus' article, and after that, tyes References quick reference.
Update:As I just noticed, my months go from 0 to 11, so $month = 2 means March now and not February. That's something you should be aware of...
|
|---|