in reply to Adding scalars but with a twist..
If they are package variables, you can use symbolic references:
If not, you can use 'eval':my $sum = 0; foreach my $i (1 .. 80) { no strict 'refs'; $sum += ${"Sel${i}Ttl"}; }
Or if you want to get fancy:my $sum = 0; foreach my $i (1 .. 80) { $sum += do {eval "$Sel${i}Ttl"} }
All code untested.my $sum = 0; local $" = "+"; eval "\$sum = @{[map {qq {\$Sel${_}Ttl}} 1 .. 80]}";
|
---|
In Section
Seekers of Perl Wisdom