in reply to getting a regex to return an array of matches?

Setting $/ to undef will ignore the end-of-line markers in the file, so @filecontents will be an array containing the entire file in one element. Your foreach loop has only one item to work on, and will exit after processing it.

Try correcting that—by leaving $/ at its default value, so @filecontents has one line per element.


added in update
rmexico's (belated) explanation of why s?he's setting $/ undef tends to make my suggestion rather pointless.

Since the entire contents of the file will be read into a scalar, tirwhan's solution to use a regex to get an array from the scalar is much closer to the OP's requirement.

emc

" When in doubt, use brute force." — Ken Thompson
  • Comment on Re: getting a regex to return an array of matches?

Replies are listed 'Best First'.
Re^2: getting a regex to return an array of matches?
by rmexico (Novice) on Feb 14, 2006 at 18:16 UTC
    the reason that i'm undef'ing the file terminator, is b/c i'm parsing files that could have lines spanning more than one line, so the normal '\n' isn't applicable
      i'm parsing files that could have lines spanning more than one line

      I think a moment's thought will tell you there's a big problem with that statement!

      If you have "lines" which span more than one "line", then you're going to have to define for us what the word "line" means for you -- first at the start of the sentence and then what it means at the end of the sentence.

      To put it another way, perl is happy to let you decide what the end of a line looks like, but you don't appear to know yourself.



      ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
      =~y~b-v~a-z~s; print