Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: looping through variables

by ioannis (Priest)
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 };


Comment on Re: looping through variables
Download Code
Re^2: looping through variables
by davido (Archbishop) 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.


    Dave

      My post answered the question asked; without Sunday speeches.

      Anyone could advocate against symbolic references, but the fact remains that they remain useful, especially when exporting symbols to other namespaces - as a standard practice.

      There Shall Not Be One And Only One Responsible Way. This is Perl; when you don't know the right way , at least the many other ways that can prove useful: the lack of 'inferior' alternatives will yield you with nothing at all. The OP stood up and asked for solutions, he deserves to hear many answers.

        My post answered the question asked; without Sunday speeches.
        Yes, but either you knew better, and didn't say, in which case what you did was unethical, or you didn't know better, in which case you're not quite experienced enough to be answering questions yet.

        As this is a FAQ, you should be familar with the FAQ before answering questions, and should be responsible for your answers, lest you contribute to distractions from XY Problems.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

        My post answered the question asked; without Sunday speeches.
        if a kid asks you, "do you know where i can get some crack", and let's say you knew where to go - you would tell the kid?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-09-21 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls