develooper Front page | perl.fwp | Postings from December 2001

Re: Santa Hole 5 (wc.pl) Post Mortem

Thread Previous | Thread Next
From:
Piers Cawley
Date:
December 7, 2001 04:16
Subject:
Re: Santa Hole 5 (wc.pl) Post Mortem
Message ID:
m2lmgfxmob.fsf@bofh.org.uk
Ian Phillipps <igp_list2@tesco.net> writes:

> On Fri, 07 Dec 2001 at 10:36:50 +1100, Andrew.Savige@ir.com wrote:
>> This hole was one by Japhy with his first post in the opening
>> hours of the game.
>
>> Like hole 2, this proved very frustrating with all attempts
>> to improve on printf failing.
> Dead right :-)
>
>> --- Tim Ayers ------------------------ 21
>> #!/usr/bin/perl
>> printf"%010d\n",$.,<>
>
> Harumph. I remember something like this approach flitting through my
> mind, but, I thought, the $. would be evaluated before the <>, so it
> would be zero.
>
> Moral: try it!
>
> Hmm... why isn't it zero?

Because perl passes arguments by reference. So $. gets shoved on the
stack (as $.) and <> gets evaluated in an array context so that the
results can be shoved on the stack. So, when printf comes to read the
value of $. '<>' has already been evaluated.

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?

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