[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] From the Perl Conference 3.0 Perl quiz (2)



Vicki Brown wrote:
> 
> If you're gonna reply with a spoiler, mark it a spoiler.
> 
> If you were there, don't jump in so fast :-)
> 
> What does this print? And why?
> 
>    use constant e => 2, pi => 3;
> 
>    print e ** pi;

minor spoiler  --v


























try adding a 

  print e;

statement.  see if that explains things for you...

full spoiler --v

























the "use constant" pragma expects only two arguments,
but doesn't complain if it gets more (why?).  so what
happens is that we end up with 

  *{main::e} = sub () { 2, pi, 3 }

so:

  print e ** pi;

becomes:
  
  print 3 ** 0;  # 3 is the value of (2, pi, 3) in scalar context

which prints: 1.
--
Steve Lane <sml@zfx.com>

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe