|< 1 2 3 4 ... 6 >| | 58 Einträge, 6 Seiten |
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
#!/usr/bin/perl use warnings; use strict; my @data; my $columns = 5; open(FH,"<BLUBBER.txt") or die $!; while(my $line = <FH>) { chomp $line; my @array = (split(/[\t\s\\]/,$line))[0..($columns-1)]; foreach (@array) { s/^\s+/;/g; s/\s+$/;/g; } # foreach if ($line =~/\bBLUBB|SAND?\b/ and $line !~/\bMUSCHEL\b/){ push(@data,[@array]); } # if } # while close (FH); my $format = ''; for my $i(0..scalar(@{$data[0]})-1){ my $max = find_longest(map{$_->[$i]}@data); $format .= '%-'.$max.'s '; } for my $entry(@data){ print sprintf($format . "\n",@$entry); } open(OUTDATEN,">ZIEL.txt") or die $!; for my $entry(@data) { print OUTDATEN join(';',@$entry),"50","\n"; } close (OUTDATEN) or die $!; sub find_longest{ my $longest = 0; for(@_){ my $length = length($_); $longest = $length if($length > $longest); } return $longest; }
1
2
3
"my" variable $entry masks earlier declaration in same scope at BLUBBER.pl line 42.
syntax error at BLUBBER.pl line 16, near "/="
Execution of BLUBBER.pl aborted due to compilation errors
$line->[-1] /= 1024;
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
use strict;
use warnings;
use Data::Dumper;
my @vfile = (
's1 s2 s3 s4 32 056 KB',
's1 s2 s3 s4 32 KB',
);
my $columns = 5;
while (defined (my $line = shift @vfile)) {
# $columns ohne -1
my @array = (split(/[\t\s\\]/,$line))[0..($columns)];
# falls die 6. Spalte leer ist und kein KB da steht
if ($array[$columns]) {
my $last = pop @array;
$array[-1] .= $last if $last =~ /^\d+$/;
}
$array[-1] = sprintf('%.2f', $array[-1] / 1024);
foreach (@array) {
s/^\s+/;/g;
s/\s+$/;/g;
}
print Dumper(\@array);
}
|< 1 2 3 4 ... 6 >| | 58 Einträge, 6 Seiten |