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

Re: [ID 20000324.027] Conditionally evaluated subroutines

Nathan Torkington
March 24, 2000 06:37
Re: [ID 20000324.027] Conditionally evaluated subroutines
Message ID:
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About