http://qs1969.pair.com?node_id=252491


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