develooper Front page | perl.perl5.porters | Postings from March 2000

Re: [ID 20000324.027] Conditionally evaluated subroutines

From:
Nathan Torkington
Date:
March 24, 2000 06:37
Subject:
Re: [ID 20000324.027] Conditionally evaluated subroutines
Message ID:
14555.31893.97463.284643@prometheus.frii.com
James Duncan writes:
> I've run it under several versions of perl, and this code always
> results in Goodbye being sent to STDOUT, which strikes me as a
> little strange.

> if (1) {
>   eval { sub test { print "Hello"; }  }
> } else {
>   eval { sub test { print "Goodbye" } }
> }

Rerun your code with the -w commandline option.

  Subroutine test redefined

Named subroutine definitions are not things that may be eval-ed
with a block, as the symbol table is changed as soon as the
subroutine is compiled.  They are a run-time a nullop.

Nat



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