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

Re: [MacPerl] print while (chop($_=<F>));



>Suppose I have a file with consecutive returns, and in my script I have
>this line
>
>print $_ while (chop($_=<F>));
>
>I'm expecting the printing of the file to terminate when the consecutive
>returns are read, but apparently it's not the case. I couldn't figure out
>why not. Why not? (^_^)

chop returns the character chopped (e.g. "\n").  Since this is not "" or
"0", it evaluates to TRUE, regardless of the value of $_ after chopping.

Maybe try

  print "$_" while (chomp($_=<F>), $_);   # chomp is usually better than chop
                                           # but chop would work too

or

  print "$1" while (<F> =~ /^(.+)\n$/);




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch