in reply to Yet another does-function-exist question

sub definedWord { my( $word )= @_; return eval "use strict; my \$x= sub { $word }; 1" || ( warn("$@\n"), $@ !~ /^Bareword/ ); } @ARGV= qw( definedWord time system foo BEGIN if -e lt goto last ) if ! @ARGV; for( @ARGV ) { printf "$_:\t%sdefined\n", definedWord($_) ? "" : "UN"; }

is one interesting interpretation, producing:

definedWord: defined time: defined system: defined Bareword "foo" not allowed while "strict subs" in use at (eval 4) line + 1. foo: UNdefined BEGIN: defined syntax error at (eval 6) line 1, at EOF if: defined -e: defined syntax error at (eval 8) line 1, near "{ lt" lt: defined goto: defined last: defined

- tye        

Replies are listed 'Best First'.
Re^2: Yet another does-function-exist question (eval sub)
by kyle (Abbot) on Apr 14, 2007 at 16:33 UTC

    Neat! It seems to consider a lot of things to be defined that aren't so executable. All of these, for instance:

    @ARGV= qw( ; "foo" 123 {} [] ) if ! @ARGV; # etc. __END__ ;: defined "foo": defined 123: defined {}: defined []: defined

      As the name implies, it is meant to be passed a word. (Since non-words can't be called as subroutines without unusual syntax.)

      - tye        

      If that really matters for an example, definedWord could be just powered with regex. ++tye.

      Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
Re^2: Yet another does-function-exist question (eval sub)
by xaprb (Scribe) on Apr 14, 2007 at 17:30 UTC

    I like this idea a lot. Thanks for the suggestion.