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
Post a Comment