Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: space saving wanted!

by broquaint (Abbot)
on Apr 23, 2003 at 09:30 UTC ( #252491=note: print w/replies, xml ) Need Help??


in reply to space saving wanted!

I wondered if there was a neat way of foreaching through a list of varibles that are names sequentially
There is, but don't do it. That may sound harsh, but use of symbolic variables is almost categorically a bad thing as a certain Mr. Dominus illustrates in Why it's stupid to `use a variable as a variable name' (with follow up articles here and here).

The alternatives are either creating an array instead of dynamically generating variables, or just use a hash e.g

## using an array my @calcs = some_function(); for(@calcs[0 .. 3]) { ... } ## using a hash for my $k (map "calc$_", 1 .. 4) { do_stuff( $calc{$k} ); ... }
See. perldata for info on array slicing and the map docs for info on map.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: space saving wanted!
by Jenda (Abbot) on Apr 23, 2003 at 11:11 UTC

    Another on-topic link on MJD's site well worth reading are the notes on his Perl Program Repair Shop and Red Flags talk and the O'ReillyNet article on the same subject.

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2022-12-02 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?