home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!news!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: Why is this foreach loop exiting early?
- Message-ID: <1992Aug27.062434.4867@netlabs.com>
- Date: 27 Aug 92 06:24:34 GMT
- References: <BtM6E1.81z@well.sf.ca.us> <123@eiffel.eiffel.com>
- Sender: news@netlabs.com
- Organization: NetLabs, Inc.
- Lines: 61
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <123@eiffel.eiffel.com> ram@eiffel.com (Raphael Manfredi) writes:
- : Quoting nlane@well.sf.ca.us (Nathan D. Lane) from comp.lang.perl:
-
- You mean, Diana Lane, not Nathan. Tsk, tsk... :-)
-
- : >chop(@farms = `cat $file`);
- :
- : That is your problem. That is a "shell" behaviour. What you want is more:
-
- Nope, guess again. chop(@foo = `cat $file`) does just what the lady expects.
-
- : If the file is really big, it might be better (for memory usage) to write:
- :
- : open(FARMS, $file) || die "Can't open $file: $!\n";
- : @farms = <FARMS>; # Because $/ is "\n" and we are in array context
- : close FARMS;
-
- If you're simply going to iterate over it you might as well use:
-
- while (<FARMS>) {
- ...
- }
-
- : >The program doesn't reach the second record, or at least doesn't process it.
- : >Needless to say, it doesn't find the INDEX line either (which is why I
- : >haven't gotten that part of the processing to function). Any help would be
- : >appreciated, including suggestions on style. I do want to learn!
- :
- : So no wonder, it did not work, you were trying to process one big line,
- : and $* is 0 by default so you did not match anything I guess.
-
- Mmm. No.
-
- : Oh, BTW, I've just spot what might be a typo... Further down in your script,
- : you write:
- :
- : if ($farm =~ /INDEX/) {
- : next until /\d+/;
- : ($Seq, $rest) = split(' ', $farm);
- : }
- :
- : Surely you meant 'unless' instead of 'until'.
-
- Yes, surely.
-
- I don't know what the real problem is, but the way to solve it is to
- put print statements in to print out the value of things like $abbrev
- and $Farm{$seq} at appropriate places. A nice trick is
-
- warn $abbrev if $DEBUGGING;
-
- Then it automatically annotates it with the line number for you.
- Nothin' says that warn really has to produce a warning...
-
- If one of those variables weren't getting set the second time then the
- program might just be appending more newlines to the first output file,
- or some such.
-
- You might also try perl -d to step through it.
-
- Larry
-