Date: 28 Jun 2001 17:53:43 GMT From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) Subject: Re: Scanning a file in CGI Message-Id: <9hfqv7$k43$1@mamenchi.zrz.TU-Berlin.DE> [please don't top-post] According to Jim Melanson : > Hi, In your code below, you are promoting a number of misconceptions. > Change this: > > while() > { > ($ref,$area,$doctitle,$docnr,$doclink,$catalog,$keyw)= split(/|/); > > to this: > > my @contents = ; > close I; > chomp @contents; There is absolutely *no* advantage in reading the whole file into memory at once. Why do you propose it? > for(my $a = 0; $a <= $#contents; $a++) { There is no reason whatever to walk through the array using indexes. See below. > ($ref,$area,$doctitle,$docnr,$doclink,$catalog,$keyw)= split(/|/, ^ here... ...you might have noticed a severe bug. The "|" must be escaped in a regex. Did you test your code? > $contents[$a]); > > > This will loop through the the file in order. If you don't care if it gets > the exact order, this is faster: What are you going on about? foreach processes the elements of an array in order. You were probably thinking about a hash. Big difference. > foreach(@contents) { > ($ref,$area,$doctitle,$docnr,$doclink,$catalog,$keyw)= split(/|/, $_); [snip of huge sig & jeopardectomy] Anno