Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Adding scalars but with a twist..

by Anonymous Monk
on Feb 14, 2005 at 10:05 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found