in reply to Re: can I make my regexp match first pattern instead of last?
in thread can I make my regex match first pattern instead of last?

I have one small remaining problem, though. My data is already a large string variable instead of a filehandle. I used the filehandle in my example above because it was easy to just copy and paste. So what do I do with this "while" line in your solution if I already have the whole dataset slurped up into a variable called $fileContents?

while (defined (my $block = <DATA>))

Replies are listed 'Best First'.
Re^3: can I make my regexp match first pattern instead of last?
by GrandFather (Saint) on Oct 25, 2008 at 20:33 UTC

    Use the string as a file:

    my $fileContents; open my $scan, '<', \$fileContents; while (defined (my $block = <$scan>)) { ... } close $scan;

    Perl reduces RSI - it saves typing
      It's working! Thanks for the help!
      Using the string as a filehandle works fine. But now I get a runtime error that says "Can't use string ("") as a symbol ref while "strict refs" in use"

      on this line of code:

      open $ResultsHandle, '<', \$return;

      So how can I use strict, which is required by Perl Best Practices, and process a multi line string one line at a time?

      Thanks, Kurt

        Go here for the clear version of the question (and answers, too).