home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5528 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  1.7 KB

  1. Path: sparky!uunet!eiffel!eiffel.com
  2. From: ram@eiffel.com (Raphael Manfredi)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Why is this foreach loop exiting early?
  5. Message-ID: <123@eiffel.eiffel.com>
  6. Date: 27 Aug 92 01:26:31 GMT
  7. References: <BtM6E1.81z@well.sf.ca.us>
  8. Sender: ram@eiffel.com
  9. Organization: Interactive Software Engineering, Santa Barbara CA
  10. Lines: 37
  11.  
  12. Quoting nlane@well.sf.ca.us (Nathan D. Lane) from comp.lang.perl:
  13. >chop(@farms = `cat $file`);
  14.  
  15. That is your problem. That is a "shell" behaviour. What you want is more:
  16.  
  17. @farms = split(/\n/, `cat $file`);
  18.  
  19. If the file is really big, it might be better (for memory usage) to write:
  20.  
  21. open(FARMS, $file) || die "Can't open $file: $!\n";
  22. @farms = <FARMS>;    # Because $/ is "\n" and we are in array context
  23. close FARMS;
  24.  
  25. >The program doesn't reach the second record, or at least doesn't process it.
  26. >Needless to say, it doesn't find the INDEX line either (which is why I
  27. >haven't gotten that part of the processing to function).  Any help would be
  28. >appreciated, including suggestions on style.  I do want to learn!
  29.  
  30. So no wonder, it did not work, you were trying to process one big line,
  31. and $* is 0 by default so you did not match anything I guess.
  32.  
  33. Your style is fine -- It looks like what I am writing :-)
  34.  
  35. Oh, BTW, I've just spot what might be a typo... Further down in your script,
  36. you write:
  37.  
  38.     if ($farm =~ /INDEX/) {
  39.         next until /\d+/;
  40.         ($Seq, $rest) = split(' ', $farm);
  41.     }
  42.  
  43. Surely you meant 'unless' instead of 'until'.
  44. -- 
  45. Raphael Manfredi <ram@eiffel.com>
  46. Interactive Software Engineering Inc.
  47. 270 Storke Road, Suite #7                      / Tel +1 (805) 685-1006 \
  48. Goleta, California 93117, USA                  \ Fax +1 (805) 685-6869 /
  49.