Thread Perl-script: Reguläreausdrücke (7 answers)
Opened by bloonix at 2006-01-26 15:44

svenXY
 2006-01-26 15:32
#28390 #28390
User since
2005-09-15
33 Artikel
BenutzerIn
[default_avatar]
Hi,

ich würde das mit split machen.
Etwa so:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use strict;

my @records;
my (&#36spalte1, &#36spalte2, &#36spalte3, &#36spalte4);

my &#36dossier= "/home/blabla/datei.txt";

open(ENTREE,"&#36dossier")or die "can't open this File &#36!";
while(<ENTREE>){
  chomp;
  if (&#36. == 1) {
    (&#36spalte1, &#36spalte2, &#36spalte3, &#36spalte4) = split(/\s+/, &#36_);
  }
  else {
    my(@zahlen) = split(/\s+/, &#36_);
    push(@records, { &#36spalte1 => &#36zahlen[0], &#36spalte2 => &#36zahlen[1], &#36spalte3 => &#36zahlen[2], &#36spalte4 => &#36zahlen[3]  });
  }
}
close ENTREE;

use Data::Dumper;
print Dumper(\@records);


Ergebnis wäre dann:
Code: (dl )
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
$VAR1 = [
{
'AR-BASE' => '0',
'CAE-PACK' => '0',
'EMS-PACK' => '0',
'case' => '1'
},
{
'AR-BASE' => '0',
'CAE-PACK' => '1',
'EMS-PACK' => '1',
'case' => '2'
},
{
'AR-BASE' => '~0',
'CAE-PACK' => '0',
'EMS-PACK' => '0',
'case' => '3'
},
{
'AR-BASE' => '~0',
'CAE-PACK' => '1',
'EMS-PACK' => '1',
'case' => '4'
}
];


Gruss,
Sven\n\n

<!--EDIT|svenXY|1138286496-->

View full thread Perl-script: Reguläreausdrücke