Sorry, not at computer. You have records separated by "Time: ". As you loop through the record, you put the lines in an array by splitting on the new line character. The first element, or line, will contain the timestamp. You would need to loop through the elements of the array and do a regexp match, capturing the part of the line you want. But leave the existing test in there so you only loop through the record that have the interesting line.
Update: added code example
Here's a simplified example. I would not split into lines but use capturing regexps on the whole record, but doing the split into lines may may it simpler for you to see what's going on.
#!/usr/bin/perl use strict; use warnings; use feature qw/ say /; use DateTime::Format::Strptime qw/ strptime /; say 'RTHROTTLED incidents:'; $/ = 'Time: '; while ( my $record = <DATA> ) { if ( $record =~ /ESME_RTHROTTLED/ ) { my @lines = split "\n", $record; # We know the time is in the first line my $time = strptime('%d/%m/%Y-%T.%3N', $lines[0])->strftime('%FT% +T.%3N'); my $ESME; foreach my $line ( @lines ) { $ESME = $1 if $line =~ /ESME:\s+(.+$)/; } say ' ' . "$time $ESME"; } }
In reply to Re^3: Parsing text string in Perl
by 1nickt
in thread Parsing text string in Perl
by gbwien
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |