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

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

Thread Previous | Thread Next
From:
Vladi Belperchinov-Shabanski
Date:
December 7, 2001 05:19
Subject:
Re: Santa Hole 5 (wc.pl) Post Mortem
Message ID:
3C10C165.29696252@biscom.net
BooK wrote:
> 
> En réponse à Piers Cawley <pdcawley@bofh.org.uk>:
> 
> > Ian Phillipps <igp_list2@tesco.net> writes:
> > >> --- 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!

first I thought `but of cource', a bit later I was a bit confused... :)

more clear would be something like:

<>;printf"%010d\n",$.

which does not work?! as I see it this is void context, but seems like I'm wrong
'cos it takes away one line... well list context can be forced:

@_=<>;printf"%010d\n",$.

I don't know why I did something like

printf"%010d\n",$_=@_=<>

which is the same :)

> > >
> > > 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.
> 
> So I guess
> 
> #!/usr/bin/perl
> printf"%010d\n","$.",<>

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <cade@biscom.net> <cade@datamax.bg>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...
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