Go back to the if-elsif-else! Stringy eval should be a last resort!

Besides, treating all of the references the same doesn't make much sense. Sure, I can see wanting to allow both @array and [list], but if you end up wanting to support refs to hashes, then it is unlikely that what you'll want to return is %$href (more likely you'll want to return just the keys or just the values, or have the hash keys have meanings...). And what possible value is there to allow \$value instead of just $value?? Or for letting the user pass in a code reference rather than forcing them to be the one to dereference it?

Sure, I've written functions where if one of the arguments is a code ref, I take special action. But that special action is never to just call the code in order to get the list. That would be a waste!

Even for the list vs. ref-to-array cases, I'd usually end up going the other direction: turning the list into an array ref! The whole point of allowing someone to pass in a reference to a list is usually that the list might be quite long and you don't want to have to copy that big list of values just to pass them to some subroutine. But your code just causes lots of extra copying to happen so just don't support refs to anything if that is all you are going to do with them!

(:

        - tye (but my friends call me "Tye")

In reply to (tye)Re: Eval and $@% ... by tye
in thread Eval and $@% ... by dragonchild

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.