in reply to help needed on a foreach loop from hell!!!

You've got a bit of a mish-mosh. I think you're trying to read in the entire file into memory, in @file, judging from this: @file = <FILE>; However, when you combine that with $/=undef, you get one long string from the <FILE>, which gets put in the first element of the array. TheDamian once gave an excellent description of what $/ does: "it tells Perl where to stop reading".

Two common idioms are:

  1. undef $/; $var = <FILE>;
  2. This reads the whole file into the scalar variable $var.
  3. @array = <FILE>;This reads the entire file into @array, one line per element (where "line" is again defined by the contents of $/).
Select one or the other technique; combing both gives strange effects, as you've found.

In the preceding node, Ineffectual has noted some strange things as well. The one I find most perplexing is that you're sub definition is in the middle of a loop. Also, it looks like the error message your die prints after not being able to open the file came from a monastery copy-and-paste: it's got a + in the middle of the $!.

HTH

Replies are listed 'Best First'.
Re: Re: help needed on a foreach loop from hell!!!
by Kentdn (Novice) on Jan 25, 2002 at 03:04 UTC
    Thanks for everybodies help the suggestions have been great and I have learnt a lot from them; everybodies input has been greatly appreciated!!!