develooper Front page | perl.perl5.porters | Postings from August 2001

Re: How to redefine sub that has prototypes without warning at runtim e?

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
August 17, 2001 22:33
Subject:
Re: How to redefine sub that has prototypes without warning at runtim e?
Message ID:
20010818013307.A641@blackrider
On Fri, Aug 17, 2001 at 04:04:03PM -0500, Neulinger, Nathan wrote:
> The following snippet generates the following warning:
> 
> ---
> sub foo () { print "foo"; }
> undef &foo;
> eval 'sub foo () { print "bar"; }';
> ---

Drop the C<undef &foo> and use a C<no warnings 'redefine'>

    {
        no warnings 'redefine';
        eval q{ sub foo () { print "bar"; } };
    }

I actually prefer sticking a code ref onto the symbol table than
mucking with eval().

    {
        no warnings 'redefine';
        *foo = sub () { print "bar"; };
    }

no quoting issues.


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
Your average appeasement engineer is about as clued-up on computers as
the average computer "hacker" is about B.O.
	-- BOFH

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About