On Nov 29, Sukhpreet Singh said:

>hmmm...interesting. it doesn't give me that error but this one lined perl
>program ends after the first line of input. doesn't wait for EOF i.e. any
>thoughts?

Due to a bug in Perl, sadly.

>print reverse(chomp @lines = <STDIN>);

That gets parsed as:

  print reverse((chomp @lines) = <STDIN>);

Now, chomp() returns a scalar, so <STDIN> is called in scalar context, and
one line is returned.  Technically, there should be an error message
"Can't modify return value of chomp()" but there isn't.  And then you get
your one-element list reversed.

First let me tell you what you're doing wrong.  chomp() does not return
the modified strings, it returns the NUMBER of elements it chomped.

  @a = ("yes\n", "no", "no", "no", "yes\n");
  print chomp @a;  # 2

If you want the chomp()ed elements, you have to use two steps.

  chomp(@lines = <STDIN>);
  print reverse @lines;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to