Leser: 24
1
2
3
4
5
6
7
8
9
Message = NPU$xy123/08Aug12344,ABS
Message = NPU$xy123/08Aug12344,ASR
Message = NPU$xy123/08Aug12344,ASR
Message = NPU$xy123/08Aug12344,ABS09
Message = NPU$xy123/08Aug12344,ACT12
Message = NPU$xy123/08Aug12344,ABS
Message = NPU$xy123/08Aug12344,ASR/88
Message = NPU$xy123/08Aug12344,ANTI
Message = NPU$xy123/08Aug12344,ANTI2
$found{'ABS'}++
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
#!/usr/bin/perl use strict; use warnings; my %keys; while(my $line=<DATA>) { $keys{$1}++ if($line=~/,(.+?)$/); } while (my ($key,$val)= each(%keys)) { print "$key = $val\n"; } __DATA__ Message = NPU$xy123/08Aug12344,ABS Message = NPU$xy123/08Aug12344,ASR Message = NPU$xy123/08Aug12344,ASR Message = NPU$xy123/08Aug12344,ABS09 Message = NPU$xy123/08Aug12344,ACT12 Message = NPU$xy123/08Aug12344,ABS Message = NPU$xy123/08Aug12344,ASR/88 Message = NPU$xy123/08Aug12344,ANTI Message = NPU$xy123/08Aug12344,ANTI2
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# -----------------------------------------------------------------------------
# File name : sort_list.pl
# Location : FRA
# Last edited by :
# Last Checkin : 11.08.2009
# Revision : 0.1
# -----------------------------------------------------------------------------
# History:
#
#
# 11.08.2009 first version
#
# -----------------------------------------------------------------------------
#
#
#
# Last change: 11.08.2009 XXX
#
################################################################################
#
#
# ------------------------------------------------------------------
# Loaded Modules
# ------------------------------------------------------------------
use strict;
use warnings;
use threads;
use threads::shared;
#
#
# ------------------------------------------------------------------
# File open
# ------------------------------------------------------------------
open (OUT, "<result_NPU_org.txt") or die $!;
#
#
# ------------------------------------------------------------------
# Search Strings
# ------------------------------------------------------------------
my @string = qw (FQTV PSPT SNR BAGL BAGT UPG MSG);
#
#
# ------------------------------------------------------------------
# Start threads
# ------------------------------------------------------------------
my $StopDotPrintFlag : shared;
$StopDotPrintFlag = 0;
my $Interval = 1;
my $DotPrintThread=threads->new(\&DotPrintThread, $Interval);
sub DotPrintThread
{
my ($Interval, @Trash) = @_;
use IO::Handle;
autoflush STDOUT 1;
my $IntervalCount=0;
print "\n\tpls. wait getting data ";
while ($StopDotPrintFlag != 2)
{
if ($StopDotPrintFlag == 1)
{
print STDOUT ".";
}
$IntervalCount++;
sleep $Interval;
}
return $IntervalCount;
}
#
#
# ------------------------------------------------------------------
# start search
# ------------------------------------------------------------------
my %keys;
while (my $line=<OUT>)
{
for my $string (@string)
{
$keys{$1}++ if($line=~ /,($string)/);
}
$StopDotPrintFlag = 1; #Stop threads
}
#
#
# ------------------------------------------------------------------
# get search result
# ------------------------------------------------------------------
while (my ($key,$val)= each(%keys))
{
print "\n$key = $val\n";
}
#
#
# ------------------------------------------------------------------
# File close
# ------------------------------------------------------------------
close OUT;
#
#
#****************************
# End of Script
#****************************
$keys{$string}++ if($line=~/,$string$/);
1 2 3 4 5 6 7 8 9 10
# kommt sowas dabei heraus: # FQTV|PSPT|SNR|BAGL|BAGT|UPG|MSG # "|" bedeutet "oder" my $search=join('|',@string); my %keys; while (my $line=<OUT>) { $keys{$1}++ if($line=~ /,($search)$/); $StopDotPrintFlag = 1; #Stop threads }
1
2
3
4
5
6
7
my $search=join('|',@string);
my %keys;
while (my $line=<OUT>)
{
$keys{$1}++ if($line=~ /,($search)$/);
$StopDotPrintFlag = 1; #Stop threads
}
2009-08-11T13:33:51 Hagen[...]
So mal eher als allgemeine Frage, muss ich Variablen initialisieren (in diesem Fall das $key{$1}++)?
[...]
2009-08-11T13:14:36 topegkeine Ahnung ob das wichtig ist, aber Wenn ich mir dein Beispiel der Datei ansehe, dann kommt es bei deiner Regexp zu Überschneidungen:
"ABS" wird auch auf "ABS09" matchen und "ASR" auch auf "ASR/88"