Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Yet another does-function-exist question

by kyle (Abbot)
on Apr 14, 2007 at 16:29 UTC ( #610081=note: print w/replies, xml ) Need Help??

in reply to Yet another does-function-exist question

This also does not work with built-ins:

use List::Util qw(min); sub foo {} $x = time(); foreach my $thing ( qw( x foo min time ) ) { printf "$thing is code: %s\n", ( ref *{$main::{$thing}}{CODE} ) ? 'Yes' : 'No'; } __END__ x is code: No foo is code: Yes min is code: Yes time is code: No

Perhaps you could tell us what problem you're really trying to solve?

If you have some string, and you want to know if it could do something under eval without actually executing it, perhaps you could use 'perl -c' for that. Or, to be really ugly, shell out and see what 'perldoc -f' has to say about it (being very careful about quoting the argument, of course). That would detect built-ins, and you could use one of the other methods listed here for detecting everything else.

Replies are listed 'Best First'.
Re^2: Yet another does-function-exist question
by xaprb (Scribe) on Apr 14, 2007 at 17:28 UTC

    I'm trying to examine a string of input and decide which words m/\b(\w+)\b/g are executable, without executing them. If executable I leave them alone; if not I do something off-topic with them.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://610081]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2021-01-26 19:07 GMT
Find Nodes?
    Voting Booth?