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

Sébastien Aperghis-Tramoni maddingue at free.fr
Mon Nov 19 13:58:50 GMT 2007


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.

-- 
Sébastien Aperghis-Tramoni

Close the world, txEn eht nepO.


More information about the london.pm mailing list