Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: looping through variables

by ioannis (Abbot)
on Jul 04, 2006 at 04:55 UTC ( #559085=note: print w/replies, xml ) Need Help??

in reply to looping through variables

The standard way is to use symbolic references; provided, of course, that your variables are on the stash.
no strict 'refs'; print ${ 'website_'. 3 };

Replies are listed 'Best First'.
Re^2: looping through variables
by davido (Cardinal) on Jul 04, 2006 at 05:19 UTC

    That's not the standard way, it's one of the standard mistakes.

    Decades of advances in computer science have gotten us to a point where dangerous practices such as "variable names for variables" (symbolic references) are usually superceeded by better, safer, saner alternatives. It's irresponsible to misrepresent symbolic references as the "standard way" to do something that really ought to be done with an array, a hash, or first class references.

    Just because Perl makes it possible to write fragile, bug prone, unsafe code doesn't mean doing so is necessarily the standard for Perl. To the contrary, living up to the standards of Perlish best practices dictates that the use of symbolic references is to be avoided in production code. Forget they exist, and you'll be in much better shape. Leave their use to the people who wrote Exporter, and other gluttons for punishment.

    I certanly hope the OP has the sense to listen to the voices of reason here, avoiding the use of symbolic references in favor of better strategies. I hope that your advice will be ignored, despite its apparent simplicity. That simplicity is dangerously seductive. The reality is that what appears simple at the outset can lead to hellish difficulty down the road.


    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2020-06-01 16:47 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (5 votes). Check out past polls.