[OT] best way to determine existence of a function in a package

Dirk Koopman djk at tobit.co.uk
Mon Nov 19 14:50:09 GMT 2007


Sébastien Aperghis-Tramoni wrote:
> Nicholas Clark wrote:
> 
>> You also can used exists and defined to see whether a subroutine
>> respectively has been declared and defined:
>>
>> $ perl -le 'print exists &Pie; print defined &Pie'
>>
>>
>> $ perl -le 'sub Pie; print exists &Pie; print defined &Pie'
>> 1
>>
>> $ perl -le 'sub Pie {} print exists &Pie; print defined &Pie'
>> 1
>> 1
>>
>>
>> I'm not sure when that use of exists became legal. I think that defined has
>> been there for a lot longer
> 
> This usage of exists() became legal in 5.6:
> 
>   $ /usr/local/perl/5.5.4/bin/perl -le 'print exists &Pie; print defined &Pie'
>   exists operator argument is not a HASH element at -e line 1.
> 

Sadly, I have some redhat 6.2 users with perl 5.005_03, and although the 
above one liner does not work, fortunately for me:-

  perl -le 'sub Pie {}; print defined &Pie'
1

Does.



More information about the london.pm mailing list