Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Adding scalars but with a twist..

by Anonymous Monk
on Feb 14, 2005 at 10:05 UTC ( #430731=note: print w/replies, xml ) Need Help??


in reply to Adding scalars but with a twist..

If they are package variables, you can use symbolic references:
my $sum = 0; foreach my $i (1 .. 80) { no strict 'refs'; $sum += ${"Sel${i}Ttl"}; }
If not, you can use 'eval':
my $sum = 0; foreach my $i (1 .. 80) { $sum += do {eval "$Sel${i}Ttl"} }
Or if you want to get fancy:
my $sum = 0; local $" = "+"; eval "\$sum = @{[map {qq {\$Sel${_}Ttl}} 1 .. 80]}";
All code untested.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2022-05-28 01:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (98 votes). Check out past polls.

    Notices?