in reply to matching everything between over two lines

Hi minixman, here is one way to do it.

use strict; local $/; my $str = <DATA>; while ($str =~ /Message dump:((?:(?!Message dump:).)*)/gs) { print "$1"; } __DATA__ Message dump: 1=4 11:13:2006 Message dump: 1=445=3=56=23=67=23=123=12=34 11:13:2006 Message dump: output: 1=4 11:13:2006 1=445=3=56=23=67=23=123=12=34 11:13:2006

Prasad

Replies are listed 'Best First'.
Re^2: matching everything between over two lines
by minixman (Beadle) on Feb 23, 2006 at 10:22 UTC
    I gave that a go with the following, as i am passing the file in from the command line.
    open(FG,"$ARGV[0]") || die &writelog(1,"INFO: processfile_rt: Unable t +o open log file: $!"); my $str = <FG>; while($str =~ /Message dump:((?:(?!Message dump:).)*)/gs) { print "$1\n"; }
    But that does not seem to print out anything.

    file is
    Message dump: 460 05/12/21 11:41:18:000 Sent FIX Message Message dump: 461 05/12/21 11:41:23:593 Received FIX message Message dump: 462 05/12/21 11:41:48:093 Sent FIX Message Message dump: 463 05/12/21 11:41:55:625 Received FIX message Message dump: 464 05/12/21 11:42:18:015 Sent FIX Message Message dump: 465 05/12/21 11:42:27:531 Received FIX message Message dump:

      You are reading the file line by line, but try matching across lines in your regular expression. That can't work. Either read the whole file into memory and then try the while loop or set the Record Separator $/ to Message dump:, or use the .. operator:

      while (<>) { print if ! /^Message dump:$/) };
      your code appears to only read the first line of the file. Try my $str=join("",<FG>); instead of the second line.
Re^2: matching everything between over two lines
by minixman (Beadle) on Feb 23, 2006 at 10:30 UTC
    Sorry i was missing the local $/ read the file at once, i think it works now