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

Re: [MacPerl] Read Speed



At 11.07 12/14/97, Johan Almqvist wrote:
>Why does everyone always load the entire file into memory?
>
>Something like
>
>while (<IN>)
>{ print OUT "chop($_) ";}
>
>should be a lot more effective (if chop is what i'm thinking it is...)

No, that will not work.  First, that will output the following for a line
that is "hello there!":

chop(hello there!)

Second, you would not use chop, but chomp.  Chop takes off the last
character of the string; chomp removes the last character online if it is a
line break character.

Third, chop/chomp returns 1 if successful, 0 if not; it does not return the
string.  So if you did C<print OUT chomp($_);>, you would get 1 or 0, not
the line.

while(defined(<IN>)) {
  chomp;
  print OUT "$_ ";
}


--
Chris Nandor               pudge@pobox.com           http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==                    MacPerl: Power and Ease                     ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#



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