From: tchrist@convex.COM (Tom Christiansen)
Subject: Re: Ode to Eval
Date: 19 Jul 91 05:31:42 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)

From the keyboard of ted@evi.com (Ted Stefanik):
:I thought Perl currently supports number 5 more efficiently via symbol table
:manipulation.  To prove it, I wrote the following little test program:
:
:################################## Cut Here ###################################
:#!/usr/bin/perl
:sub foo
:{
:    return undef;
:}
:
:@syms = ("foo", "bar");
:
:foreach $sym (@syms)
:{
:    ($user,$system) = times;
:
:    for ($i = 1;  $i < 10000;  $i++)
:    {
:        {                               # Why are these braces necessary ???
:            *entry = $_main{$sym};
:            $defined = defined(&entry);
:        }                               # Why are these braces necessary ???
:    }
:}

You know, I just wrote this little isdef function:

    sub isdef { 
	local($function);
	local(*entry);
	for $function (@_) {
	    *entry = $_main{$function};
	    return 0 unless defined &entry;
	}
	1;
    } 

And got a coredump.  Adding an extra set of braces didn't help.  

This did:

    sub isdef { 
	local($function);
	for $function (@_) {
	    local(*entry) = $_main{$function};
	    return 0 unless defined &entry;
	}
	1;
    } 



    sub checkdef {
	print join(', ', @_), 
	      @_ == 1 
		  ? " is " 
		  : " are ", 
	      &isdef  
		  ? "" 
		  : "not ",
	      "defined\n";
    } 

    &checkdef('abc');
    &checkdef('xyz', 'pdq');
    &checkdef('isdef');
    &checkdef('abc','isdef');
    &checkdef('isdef','abc');
    &checkdef('isdef','checkdef');
    &checkdef('isdef','checkdef', 'abc');

I realize I don't want all those entries around, but 
on the other hand, I'm not going to be calling this 
with extremely long lists.  And Larry does warn against
anything but this. 

--tom
--
"GUIs normally make it simple to accomplish simple actions and impossible
to accomplish complex actions."   --Doug Gwyn  (22/Jun/91 in comp.unix.wizards)

     Tom Christiansen           tchrist@convex.com      convex!tchrist

------------------------------

