Leser: 25
1
2
3
S/R Sending command
---------------------------------------------------------------------------
NRT CC/1234567890
Quote# $LAST_SUBMATCH_RESULT
# $^N
The text matched by the used group most-recently closed (i.e. the group with the rightmost closing parenthesis) of the last successful search pattern. (Mnemonic: the (possibly) Nested parenthesis that most recently closed.)
This is primarily used inside (?{...}) blocks for examining text recently matched. For example, to effectively capture text to a variable (in addition to $1 , $2 , etc.), replace (...) with
1. (?:(...)(?{ $var = $^N }))
By setting and then using $var in this way relieves you from having to worry about exactly which numbered set of parentheses they are.
This variable is dynamically scoped to the current BLOCK.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use strict;
use warnings;
while (defined(my $line = <DATA>)) {
chomp($line);
#
if ($line =~/S\/R Sending command\r?\n-+\r?\nNRT CC\/(\d+)/) {
print "$1\n$line\n";
} # if
} # while
__DATA__
S/R Sending command
---------------------------------------------------------------------------
NRT CC/1234567890
2009-08-18T14:40:44 RamboOK hab ich gemacht und für das Bsp. mit __DATA__ funktioniert es jetzt auch.
Aber wenn ich das ganze auf eine Logfile Datei los lasse bekomme ich wieder keine Ausgabe. Egal ob mit oder ohne "local $/"
[...]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use strict;
use warnings;
use Tie::File;
use Archive::Zip;
use Archive::Zip::MemberRead;
use File::Glob ':glob';
my $Zip_File = "test.zip";
my $zip = new Archive::Zip($Zip_File);
my @file2 = $zip->membersMatching( '.*' );
for my $file2 (@file2){
my $fh = new Archive::Zip::MemberRead($zip, $file2);
my $fh2 = $file2->fileName();
local $/;
while (defined(my $line = $fh->getline())) {
chomp($line);
#
if ($line =~/S\/R Sending command\r?\n-+\r?\nNRT CC\/(\d+)/) {
print "$1\n$line\n";
} # if
} # while
$fh->close();
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use strict; use warnings; open (LOG, "log.txt"); my $log; while (<LOG>) { $log .= $_; } my $zeile = 1; while ($log =~ s/\n/{([$zeile])}/o) { ++$zeile; } while ($log =~ /S\/R Sending command\{\(\[\d+\]\)\}\-+\{\(\[\d+\]\)\}NRT CC\/(\d+)/g) { my $line; my $foundstr = $&; if ($foundstr =~ /\{\(\[\d+\]\)\}/o) { $line = $&; } if ($line =~ /\d+/) { $line = $&; } $foundstr =~ s/\{\(\[\d+\]\)\}/\n/g; print "$foundstr\nAt line: $line\n\n"; }
if ( index( $line, $String, 0 ) >= 0 .. index( $line, $end_line, 0 ) >= 0 ) {