[RFC] Text::Echelon v0.01

Wilson, Andrew (Belfast) Andrew.Wilson at trw.com
Tue Dec 18 04:53:10 CST 2001


Hi

> -----Original Message-----
> From: Tony Bowden [mailto:tony at kasei.com]
> Sent: 17 December 2001 19:46
> 
> On Mon, Dec 17, 2001 at 05:22:13PM +0000, Wesley Darlington wrote:
> > On Mon, Dec 17, 2001 at 04:23:21PM -0000, Wilson, Andrew (Belfast)
> > > > From: Wesley Darlington [mailto:wesley at yelsew.com]
> > > >     chomp, push @wordlist, $_ for <DATA>;
> 
> > > Doesn't that chomp the return value of push, which is the 
> > > number of elements added to the array?
> > Does it?
> 
> Nope.
> 
> It's really not that hard to test these things before 
> posting, you know!
> 
> With a wave of the hands, I conjure a test script from an 
> earlier post:
> 
> # chomp(my @array = <DATA>);
> chomp, push @array, $_ for <DATA>;
> 
> local $" = "><";
> print "We have <@array>\n";
> __DATA__
> foo
> bar
> baz
> 
> Now, for pennance, Andrew can explain why it *does* work ...

Just proves you shouldn't comment on these things when you don't have
a sensible version of perl for testing them with.

why does it work?  because of the comma operator after the chomp.  It
evaluates
the expression 

  chomp, push @array, $_ 

for each value that it reads from <DATA>.  The chomp followed by the comma
chomps $_ by default and the the push is done.  A fuller version would be

for (<DATA>) {
  chomp;
  push @array, $_
}

which I _think_ is what perl is actually doing here.  Am I right?

cheers

Andrew



More information about the Belfast-pm mailing list