why not? Because it is bad? Because it is bad style? Because it will lead to unexpected results? I don't mean to be argumentative, but just telling me I shouldn't is not satifying.
Well, you already indicated that you saw the musings of Mark Jason Dominus about this subject. Perhaps you should reread them. He did a much better job than I can.

or I could just
&$action;
but I can't because that is not allowed under use strict; so I
eval($action);
That's just plain stupid. If you really want to do something that strict prevents you from doing, you shouldn't code your way around it - just turn strictness (locally) off. Using eval in this case, is like entering the house through the chimney, because the door is closed, but unlocked.
Imagine if I had a lot of choices for action -- that would be a lot of if statements.
No. You'd use a reference to the function you want to execute, or you use a hash. &$action could be dangerous. What if $action contains a string for which there isn't a subroutine by that name? Or worse, a name of a subroutine which really shouldn't be called right now? Please reread Mark Jasons articles again. They explain the dangers.

Note that I'm not saying that you should never use symbolic references. But as long as you don't understand the dangers, don't use them. Don't play with matches before you understand fire either.

Abigail


In reply to Re: another 'array to hash' question by Abigail-II
in thread another 'array to hash' question by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.