Leser: 1
4 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
use Time::HiRes qw(gettimeofday);
my $t0 = gettimeofday();
"Meine Operationen"
my $t1 = gettimeofday();
my $elapsed = $t1 - $t0;
print "$elapsed Sekunden \n";
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
use strict;
use warnings;
use Getopt::Long;
use IO::File;
use File::Glob;
use Data::Dumper;
use File::Find;
use Time::HiRes qw(gettimeofday);
# the cmd-line-arg --output
my $output = 0;
GetOptions(
'output=s' => \$output,
);
my $fh1 = new IO::File;
my $fh2 = new IO::File;
my $fh3 = new IO::File;
my $write_context = "context.csv";
my $write_message = "message.csv";
my @logfilelist =glob("*.log");
my @array;
my $line;
my $counter=0;
my $item=0;
my $MessageFound=0;
my @list;
my $t0 = gettimeofday();
foreach my $file(@logfilelist) {
my $tmp_file=substr($file,0,-4);
$fh1->open("> h:/$tmp_file-$write_context") || die "$write_context kann nicht erzeugt werden";
$fh2->open("> h:/$tmp_file-$write_message")|| die " $write_message kann nicht erzeugt werden";
$fh3->open("<$file") || die "$file konnte nicht zum lesen geöffnet werden";
while(<$fh3>)
{
if(/Context:/)
{
$line = chomp($_);
$line= substr($_,10,length($_));
@array = split(/ /, $line);
$line='';
#print $fh1 Data::Dumper->Dump([\@array], [' split / /']);
#print $fh1 "$counter;",@array,"\n"
#print $fh1 @array, "\n";
foreach my $idx (0 .. 5) {
$array[$idx].=";"
}
if($array[2] ne ";")
{
$counter++;
#$MessageFound=0;
#print $fh1 Data::Dumper->Dump([\@array], [' split / /']);
print $fh1 "$counter;",@array,"\n"
}
}
if(/Message:/ || $MessageFound)
{
if($array[2] ne ";")
{
$MessageFound=1;
if($_ =~ /^\n/)
{
chomp($line);
$line .= "/ende\n";
print $fh2 "$counter|$line";
$line = '';
$MessageFound=0;
}
else
{ chomp($_);
$line .= $_
};
}
}
}
}
$fh1->close;
$fh2->close;
my $t1= gettimeofday();
my $elapsed = $t1 - $t0;
print "$elapsed Sekunden \n";
Quoteindex STR,SUBSTR,POSITION
index STR,SUBSTR
The index function searches for one string within another, but without the wildcard-like behavior of a full regular-expression pattern match. It returns the position of the first occurrence of SUBSTR in STR at or after POSITION. If POSITION is omitted, starts searching from the beginning of the string. The return value is based at 0 (or whatever you've set the $[ variable to--but don't do that). If the substring is not found, returns one less than the base, ordinarily -1.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
substr EXPR,OFFSET,LENGTH,REPLACEMENT
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
Extracts a substring out of EXPR and returns it. First character is at offset 0, or whatever you've set $[ to (but don't do that). If OFFSET is negative (or more precisely, less than $[), starts that far from the end of the string. If LENGTH is omitted, returns everything to the end of the string. If LENGTH is negative, leaves that many characters off the end of the string.
You can use the substr() function as an lvalue, in which case EXPR must itself be an lvalue. If you assign something shorter than LENGTH, the string will shrink, and if you assign something longer than LENGTH, the string will grow to accommodate it. To keep the string the same length you may need to pad or chop your value using sprintf.
If OFFSET and LENGTH specify a substring that is partly outside the string, only the part within the string is returned. If the substring is beyond either end of the string, substr() returns the undefined value and produces a warning. When used as an lvalue, specifying a substring that is entirely outside the string is a fatal error. Here's an example showing the behavior for boundary cases:
my $name = 'fred';
substr($name, 4) = 'dy'; # $name is now 'freddy'
my $null = substr $name, 6, 2; # returns '' (no warning)
my $oops = substr $name, 7; # returns undef, with warning
substr($name, 7) = 'gap'; # fatal error
An alternative to using substr() as an lvalue is to specify the replacement string as the 4th argument. This allows you to replace parts of the EXPR and return what was there before in one operation, just as you can with splice().
4 Einträge, 1 Seite |