in reply to Re: Comparing references to sub's
in thread Comparing references to sub's
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
|
|---|