![]() |
|< 1 2 >| | ![]() |
19 Einträge, 2 Seiten |
print DATAOUT join "", /URSPRUNG=(\d*)/, /CODE=(\d*)/, "VOL", /VOL=(\d*)/, /&(\d*)/g, "\n" while <DATAIN>;
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
use Tie::File;
my @file;
tie @file, 'Tie::File', $filename or die "Error: couldn't tie $filename to array: $!\n";
# jedes element von @array entspricht jetzt einer zeile
foreach my $line (@file) {
my %data = &ParseLine($line);
# mach was mit %data; zum aendern einer Zeile einfach $line neu bilden
} # foreach
untie(@array);
# -----------------------------------------------------
sub ParseLine {
my ($line) = @_;
my %data = ();
foreach my $item (split(/,/, $line)) { # item ist z.B. "Ursrpung=001"
# $key ist z.B. "Ursprung", $value z.B. "001"
my ($key, $value) = split(/=/, $item, 2);
# in hash speichern; achtung, falls ein key mehrere werte hat, bleibt nur
# der letzte
$data{$key} = $value;
} # foreach
return %data;
} # ParseLine
print DATAOUT join "", /URSPRUNG=(\d*)/, /CODE=(\d*)/, "VOL", /VOL=(\d*)/, /&(\d*)/g, "\n" while <DATAIN>;
1
2
3
4
5
open DATAIN, 'file.txt' or die $!;
open DATAOUT, '>outputfile.txt' or die $!;
print DATAOUT join "", /URSPRUNG=(\d*)/, /CODE=(\d*)/, /VOL=([\w\&]*)/, "\n" while <DATAIN>;
close DATAIN;
close DATAOUT;
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
unless (open (FH, $filename)) { die "Error: couldn't read '$filename': $!"; } while (<FH>) { chomp($_); # zeilenumbruch am ende killen my %items = &ParseLine($_); # mach was mit %items } # while close (FH); # ----------------------------------------------------- sub ParseLine { my ($line) = @_; my %data = (); foreach my $item (split(/,/, $line)) { # item ist z.B. "Ursrpung=001" # $key ist z.B. "Ursprung", $value z.B. "001" my ($key, $value) = split(/=/, $item, 2); # in hash speichern; achtung, falls ein key mehrere werte hat, bleibt nur # der letzte $data{$key} = $value; } # foreach return %data; } # ParseLine
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
#! /usr/bin/perl
use strict;
use warnings;
my %hash;
while(my $line = <DATA>){
my %inner_hash;
foreach my $item(split(/,/,$line)){
my ($key,$val) = split(/=/,$item);
$key =~ s/[^\w]//g;
$val =~ s/[^\w&]//g;
$inner_hash{$key} = $val;
}
push(@{$hash{$inner_hash{URSPRUNG}}},\%inner_hash);
}
foreach my $key(keys(%hash)){
foreach my $elem(@{$hash{$key}}){
my ($base,@vols) = split(/&/,$elem->{VOL});
foreach(@vols){
print $key," ",$elem->{CODE}," ",$base.$_,"\n";
}
print $key," ",$elem->{CODE}," ",$base,"\n" unless(@vols);
}
}
# _ _DATA_ _ ohne Leerzeichen!!
_ _DATA_ _
:URSPRUNG=123,CODE=320317440,VOL=0&1&2&3&4&5&6&7&8&9!
:URSPRUNG=123,CODE=3203177290,VOL=0&1&2&3&4&5&6&7&8&9!
:URSPRUNG=123,CODE=320317770,VOL=0&1&2&3&4&5&6&7&8&9!
:URSPRUNG=123,CODE=32021883,VOL=3&4&5!
:URSPRUNG=123,CODE=4203204,VOL=4&5&6&7!
:URSPRUNG=125,CODE=32021883,VOL=3&4&5!
:URSPRUNG=125,CODE=4203204,VOL=4&5&6&7!
:URSPRUNG=124,CODE=32021883,VOL=3&4&5!
:URSPRUNG=124,CODE=4203204,VOL=164564&5&6&7!
:URSPRUNG=124,CODE=4203206,VOL=124&5&6!
Quote\n\n125 32021883 34
125 32021883 35
125 4203204 45
125 4203204 46
125 4203204 47
123 320317440 01
123 320317440 02
123 320317440 03
123 320317440 04
123 320317440 05
123 320317440 06
123 320317440 07
123 320317440 08
123 320317440 09
123 3203177290 01
123 3203177290 02
123 3203177290 03
123 3203177290 04
123 3203177290 05
123 3203177290 06
123 3203177290 07
123 3203177290 08
123 3203177290 09
123 320317770 01
123 320317770 02
123 320317770 03
123 320317770 04
123 320317770 05
123 320317770 06
123 320317770 07
123 320317770 08
123 320317770 09
123 32021883 34
123 32021883 35
123 4203204 45
123 4203204 46
123 4203204 47
124 32021883 34
124 32021883 35
124 4203204 1645645
124 4203204 1645646
124 4203204 1645647
124 4203206 1245
124 4203206 1246
![]() |
|< 1 2 >| | ![]() |
19 Einträge, 2 Seiten |