Perl Regex not finding pattern within script -



Perl Regex not finding pattern within script -

i'm reading contents of log file, performing regex on lines , putting results in array, reason there no output.

use strict; utilize warnings; $logfile = "log.file"; $outfile = "out.file"; open(log, "$logfile") or die ("could not open $logfile: $!\n"); open(tmp, ">", "$outfile") or die ("could not open $outfile: $!\n"); @data = (<log> =~ /<messagebody>(.*?)<\/messagebody>/sg); print tmp "this test line. \n"; foreach (@data){ print "@data\n"; print "\n=======================\n"; } close tmp; close log;

my output file (out.file) , content "this test line." know regex works because tried @ prompt with: -lne 'begin{undef $/} while (/(.*?)</messagebody>/sg) {print $1} log.file > test.file

what doing wrong?

your info spans lines.

you'll hence need slurp entire thing before using regex:

my $logdata = {local $/; <log>}; @data = $logdata =~ m{<messagebody>(.*?)</messagebody>}sg;

regex perl file-io

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -