Jemand zu Hause?
1
2
3
4
5
6
7
8
9
10
11
12
$testfile = "./workspace/testfile.log";
$ergfile = "./workspace/result.log";
open (FILE,"<",$testfile) || print "$testfile dont exist";
open (FILE2,">",$ergfile) || print "$ergfile dont exist";
@Array = <FILE>;
foreach(@Array){
; tue etwas
push (@Array2,$data);
}
print FILE2 $data;
close(FILE);
close (FILE2);
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
#!/usr/bin/perl -w
########################
# Modul Definition
#########################
use strict;
##########################
# Parameter Definition
#########################
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
my($date,$clock);
my ($suffix,$File1,$FileName,$ExtFile,$ReadFile,$line,$Ext,$ExtName,$allocDate,$AccountID,$ArraySize);
my (@Array,@Array2,@Array3,@Array4);
##########################
##########################
system("clear");
##########################
# Time-Calculation
##########################
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$date =sprintf("%04d-%02d-%02d",$year+1900,$mon+1,$mday);
$clock =sprintf("%02d:%02d:%02d",$hour,$min,$sec);
###############################
# File-Operation
print"Read-File: ";
$ReadFile = <STDIN>;chomp($ReadFile); # Read the Filename from command
$File1 = "/home/henrik/workspace/$ReadFile.log";
open (File1,"<$File1") || print "Error: Input-File dont exist";
@Array = <File1>; # Copy File 2 Array
$ArraySize = scalar(@Array);
print "Input-Array-Size: $ArraySize\n";
close(File1); # Close the Input-File
foreach(@Array){
$line = shift(@Array); # Read the next line to line-Parameter
$Ext = $1 if($line =~/EXTENSIONNUM=(\d+)/); # Extract the Extension-Number
$ExtName = $1 if(($line =~ /NAME=(\d+)/)||($line =~ /NAME=(\w+)(\d+)/));
$allocDate = $1 if ($line =~ /DATEALLOCATED=(\d+-\d+-\d+)/);
$AccountID = $1 if ($line =~ /ACCOUNTID=(\d+)/);
push(@Array3,$ExtName," ",$Ext," ",$AccountID," ",$allocDate,"\n");
push(@Array4,$Ext,"\n");
}
$ArraySize = scalar(@Array4);
print "output-Array-Size: $ArraySize\n";
print "FileName: ";
$suffix=<STDIN>;chomp($suffix);
$FileName = "/home/henrik/workspace/$suffix.log";
$ExtFile = "/home/henrik/workspace/$suffix-Extensions.log";
open (File2,">",$FileName)|| print "Error:Export-File dont writeable";
open (ExtFile,">",$ExtFile)|| print "Error: Extension-Export-File dont writeable";
print File2 @Array3;
print ExtFile @Array4;
close File2;
close ExtFile;
FILE
$in_file
!/bin/perl -w
use warnings;
2014-06-12T09:05:54 cohamaHallo muffi,
mir scheint es nicht Zielführend zu sein, wenn man sich über die unterschiedlichen Stile unterhält.
Quote
Quote
perllexwarn.QuoteWieviel Speicher wird je Variable reserviert?
QuoteWelche Auswirkungen hat der Speicherbedarf des Scripts auf die Run-Performance?
2014-06-12T08:39:06 cohamaDies möchte ich nicht durchführen. Zudem bin ich der Überzeugung, dass diese Struktur es anderen erleichtert die Kern des Scripts schnell zu verstehen.
Wie frage ich & perlintro
brian's Leitfaden für jedes Perl-Problem@Array = <File1>; # Copy File 2 Array
$count++; # increment $count
Wie frage ich & perlintro
brian's Leitfaden für jedes Perl-Problem2014-06-12T09:57:49 cohamaHallo pq,
in dem Comment steht übrigens Copy File to (alias 2) Array. Das ist ein global gültiger Kommentar.
QuoteZudem gibt es keine überflüssigen Comments in der Informatik. Diesen Standpunkt kann man ja gerne mit Herrn Prof. Dr. Björn Scheuermann diskutieren.
QuoteKurzum:
Warum beinhaltet die Ergebnis-Datei nur einen Teil des Ergebnis-Arrays?
Das ist die eigentliche Frage meines Threads.
2014-06-12T09:57:49 cohamaKurzum:
Warum beinhaltet die Ergebnis-Datei nur einen Teil des Ergebnis-Arrays?
Das ist die eigentliche Frage meines Threads.
1 2 3 4 5 6 7 8 9
foreach(@Array){ $line = shift(@Array); # Read the next line to line-Parameter $Ext = $1 if($line =~/EXTENSIONNUM=(\d+)/); # Extract the Extension-Number $ExtName = $1 if(($line =~ /NAME=(\d+)/)||($line =~ /NAME=(\w+)(\d+)/)); $allocDate = $1 if ($line =~ /DATEALLOCATED=(\d+-\d+-\d+)/); $AccountID = $1 if ($line =~ /ACCOUNTID=(\d+)/); push(@Array3,$ExtName," ",$Ext," ",$AccountID," ",$allocDate,"\n"); push(@Array4,$Ext,"\n"); }
1 2 3 4 5 6 7 8
foreach my $line( @Array ){ $Ext = $1 if $line =~ /EXTENSIONNUM=(\d+)/; # Extract the Extension-Number $ExtName = $1 if $line =~ /NAME=(\w+)/; $allocDate = $1 if $line =~ /DATEALLOCATED=(\d+-\d+-\d+)/; $AccountID = $1 if $line =~ /ACCOUNTID=(\d+)/; push(@Array3,$ExtName," ",$Ext," ",$AccountID," ",$allocDate,"\n"); push(@Array4,$Ext,"\n"); }
push(@Array3,$ExtName," ",$Ext," ",$AccountID," ",$allocDate,"\n");
open (File2,">",$FileName)|| print "Error:Export-File dont writeable";
QuoteOb Du Variablen vorher deklarierst ist eher Geschmackssache
QuoteIst Dir klar, dass in $Ext ggf. das Ergebnis eines früheren Matches steht?
2014-06-12T11:38:53 FIFOOb Du Variablen vorher deklarierst ist eher Geschmackssache
Wie frage ich & perlintro
brian's Leitfaden für jedes Perl-Problem2014-06-12T08:03:28 cohama
for my $line (@array)
while (defined(my $line = shift @array))
while (my $line = <File1>)
Wie frage ich & perlintro
brian's Leitfaden für jedes Perl-Problem2014-06-12T11:53:14 pq2014-06-12T08:03:28 cohama
du iterierst über @Array und hast dadurch das element schon automatisch in $_, dann aber holst du dir das element mit shift aus @Array raus.
geht gar nicht. also es geht schon im sinne von "ich kann den boden auch mit der zahnbürste putzen", aber nicht im sinne von klar, effizient, sinnvoll.
1 2 3 4 5
my @foo = ( 0..9 ); for ( @foo ) { my $shift = shift @foo; print "\$_: $_\t\$shift: $shift\n"; }
Wie frage ich & perlintro
brian's Leitfaden für jedes Perl-Problem1 2 3 4 5 6 7 8 9 10 11
my @foo = ( 0..9 ); my $offset = 0; print "Array: @foo"; for ( @foo ) { my $shift = shift @foo; print "\n\$offset: $offset\t\$_: $_\t\$shift: $shift\n\n"; print "Array: @foo"; $offset++; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Array: 0 1 2 3 4 5 6 7 8 9
$offset: 0 $_: 0 $shift: 0
Array: 1 2 3 4 5 6 7 8 9
$offset: 1 $_: 2 $shift: 1
Array: 2 3 4 5 6 7 8 9
$offset: 2 $_: 4 $shift: 2
Array: 3 4 5 6 7 8 9
$offset: 3 $_: 6 $shift: 3
Array: 4 5 6 7 8 9
$offset: 4 $_: 8 $shift: 4
Array: 5 6 7 8 9
Wie frage ich & perlintro
brian's Leitfaden für jedes Perl-Problem
IO::All benutzen:
Wie frage ich & perlintro
brian's Leitfaden für jedes Perl-Problemmy @list = do{ my $fh; open($fh, $file) && return <$fh> };
my @list = eval{ local @ARGV = ($file); <> };