yes , and my first attempt at this was be using strings and interpolating them as function names - was quite useful during debugging etc. But I wanted to use refs from the 'purity' aspect - I didn't want to use a name that represented a function. I also _think_ it is a 'better way' from the prespective of speed/efficiency (moderately better).

As for

 if ( $subname eq 'do_zipped_things' )...

being clearer, isn't

 if ( $ref ==  \&desired_code )...

just as clear. Refs are even better though, because you are checking that your reference really does 'point' to existing code - the string way, you have a string that 'might' also be the name of a subroutine. How do you check that the string can be 'called'?

But the really important point, that I think has been missed, is when does equating ref's to subroutines _not_ work e.g what about in anonymous namespaces, or equating methods in objects/classses, what if someone does something weird with gensym(), or plays around with the CODE entry in symbol tables, does the sub have to be exported some how from a module etc, etc


In reply to Re: Re: Comparing references to sub's by leriksen
in thread Comparing references to sub's by leriksen

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.