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

[MacPerl] Read Speed II



According to Strider:
> 
> I think I need to clarify a little bit. Herein lies my problem:
<snip>
> 
> This script CRAWLS. For a 4.7 mb file, it takes far too long. I left it for
> at least 10 minutes, and MacPerl's memory was at about 500k. Any ideas why?

The reason this script crawls is because you've used the
wrong statement on the following line:

> while (<IN>) {$data .= $_;}

This makes the incoming string concatenate onto the
pre-existing string $data.  What this means is that Perl
has to re-create the string every time you read in another
line.  So what you are getting is:

a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa

What you should have put there was this:

	@data = ();
	while( <IN> ){ $data[++$#data] = $_; }

This is equivalent to the second program and should not
take any more time than the second program.  :-)

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