Date: Thu, 28 Jun 2001 13:25:02 -0400 From: "Jim Melanson" Subject: Re: Scanning a file in CGI Message-Id: Hi, Change this: while() { ($ref,$area,$doctitle,$docnr,$doclink,$catalog,$keyw)= split(/|/); to this: my @contents = ; close I; chomp @contents; for(my $a = 0; $a <= $#contents; $a++) { ($ref,$area,$doctitle,$docnr,$doclink,$catalog,$keyw)= split(/|/, $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: foreach(@contents) { ($ref,$area,$doctitle,$docnr,$doclink,$catalog,$keyw)= split(/|/, $_); Jim President & Founder Perl Services www.perlservices.net Director of Programming, Robinson Internet Solutions www.robinsoninternet.com Founder of Charity Ware, 1997 www.charityware.ws International Who's Who of Information Technology Member since 2000 jim@perlservices.net jim@robinsoninternet.com jim@charityware.ws ICQ# 116084898 1-877-751-5900 North America 1-760-249-3676 International 1-208-694-1613 FAX "Do or do not. There is no try." --- Yoda =========================== "To do is to be" - Descartes "To be is to do" - Voltaire "Do be do be do" - Sinatra "Danny Hendrickx" wrote in message news:3B39A0E1.5837118E@alcatel.be... > Hello, > > I try to write a CGI program that scans a file line by line and prints > out the parts of the line in different variables in a table (parts are > separated by '|' in the file to be scanned). > > I used the normal perl way of scanning through the file, but apparantly > this doesn't work. All I get to see is the top row of my table, and no > entries in the table. > > Can anyone tell me what I'm doing wrong. The program is below, and below > it is the file I use for scanning. > > TIA > > #!/usr/local/bin/perl -w > > use strict; > > use CGI qw(:standard); > > my ( > $TITLE, > $HEADER, > $ref,$area,$doctitle,$docnr,$doclink,$catalog,$keyw, > $entry,@entries > ); > > $TITLE = "SS31 Document Overview"; > $HEADER = "Parm documents"; > > print header(),start_html($TITLE),h1($HEADER); > > print p("
h1($HEADER)
"); > if (param()) > { > } > else > { > print hr(); > open (I," print p(" > > > > > > "); > > while() #<== this part does not work > { > ($ref,$area,$doctitle,$docnr,$doclink,$catalog,$keyw)= split(/|/); > > if ($area eq "PARM") > { > print p(" > > > > > "); > } > > } > close I; > print p(" > > > > >
TitleNumberInternal > RefCataloged
href=\"$doclink\">$doctitle$docnr$ref>$catalog>
"); > > print end_form(),hr(); > } > print end_html; > > and the s1docs.txt file: > > 1|PARM|document 1|number 1|link 1|yes|key 1 > 2|MISC|doc 2|nr 2|lnk 2|no|key 2 > 3|PARM|doc 3|nr 6|lnk 3|no|key 3 > > -- > Regards, > ________________ > ________________________________________________\ /_____ > Feature Development Team Leader WR2A team 7 Services and SAD / > SW-Engineering - Routing - VJ33 Hendrickx Danny > phone : +32-3-240 3916 ALCATEL TELECOM > fax : +32-3-240 9899 Fr.Wellesplein 1 > mailto:daniel.hendrickx@alcatel.be 2018 Antwerp Belgium > ______________________________________________________\ /___________ > URL: http://www.se.bel.alcatel.be/CH_sector1/SS31/ \/ > ********************************************************************* > The early bird gets the worm, but the second mouse gets the cheese. > *********************************************************************