|< 1 2 >| | 11 Einträge, 2 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
sub fill_table()
{
my $datei = $_[0]; # Dateiname
my $src_path = $_[1]; # Pfad zur Datei
my $delimiter = $_[2]; # Separator
my $header = $_[3];
open (IFILE, "< $src_path$datei") or die "can't open $0: $!\n";
$z=0;
while(my $BomLine = <IFILE>)
{
$z++;
my @Bom = split(/\$delimiter/, $BomLine);
$spalten= @Bom;
$cols=$spalten;
for (0..$spalten)
{
$col=$_;
$col=$col+1;
$arrayVar->{"$z,$col"} = "$Bom[$_]";
}
}
}
&fill_table('test.txt','',"|",'1');
my @Bom = split(/\s+/, $BomLine);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#! /usr/bin/perl
use strict;
use warnings;
my $delim = '\|';
my $string = qq~test|dies|ist|ein~;
fill_table($string,"",$delim);
sub fill_table
{
my $string = $_[0]; # Dateiname
my $src_path = $_[1]; # Pfad zur Datei
my $delimiter = $_[2]; # Separator
my @Bom = split(/$delimiter/, $string);
print $_,"\n" for(@Bom);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
sub fill_table{ # die runden Klammern weg, weil das Prototyping ist!
my ($datei,$src_path,$delimiter,$header) = @_;
open (IFILE, "< $src_path$datei") or die "can't open $src_path$datei: $!\n"; # in $0 steht der Skriptname
my $z = 0;
while(my $BomLine = <IFILE>){
$z++;
my @Bom = split(/\Q$delimiter/, $BomLine); # benutz das \Q!!!
for (0..(scalar(@Bom) -1)){
$arrayVar->{$z.','.($_ + 1)} = $Bom[$_];
}
}
close IFILE; # Filehandle schließen - das hast Du komplett vergessen!
}
1
2
3
4
5
6
my $delim = '|';
my $file = 'test.txt';
my $path = '/path/';
my $head = 'irgendwas';
fill_table($file,$path,$delim,$head);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sub fill_table()
{
my ($datei,$src_path,$delimiter,$header) = @_;
open (IFILE, "< $src_path$datei") or die "can't open $src_path$datei: $!\n"; # in $0 steht der Skriptname
my $z = 0;
while(my $BomLine = <IFILE>){
$z++;
my @Bom = split(/\Q$delimiter/, $BomLine); # benutz das \Q!!!
$cols= @Bom;
for (0..(scalar(@Bom) -1)){
$arrayVar->{$z.','.($_ + 1)} = $Bom[$_];
}
}
1 while <IFILE>;
$zeilen=$.;
close IFILE; # Filehandle schließen - das hast Du komplett vergessen!
}
1
2
3
4
5
6
my $delim = '|';
my $file = 'test.txt';
my $path = '';
my $head = 'irgendwas';
fill_table($file,$path,$delim,$head);
1
2
3
4
5
6
my $delim = 's+';
my $file = 'test2.txt';
my $path = '';
my $head = 'irgendwas';
fill_table($file,$path,$delim,$head);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sub fill_table{
my ($datei,$src_path,$delimiter,$header,$type) = @_;
open (IFILE, "< $src_path$datei") or die "can't open $src_path$datei: $!\n";
my $z = 0;
while(my $BomLine = <IFILE>){
$z++;
my @Bom = ();
if($type eq 'RegEx'){
@Bom = split(/$delimiter/, $BomLine);
}
else{
@Bom = split(/\Q$delimiter/, $BomLine);
}
for (0..(scalar(@Bom) -1)){
$arrayVar->{$z.','.($_ + 1)} = $Bom[$_];
}
}
close IFILE;
}
1
2
3
4
5
6
7
my $delim = '\s+'; # wichtig: Hochkommas benutzen!
my $file = 'test2.txt';
my $path = '';
my $head = 'irgendwas';
my $type = 'RegEx';
fill_table($file,$path,$delim,$head,$type);
1
2
3
4
5
6
7
my $delim = '|';
my $file = 'test2.txt';
my $path = '';
my $head = 'irgendwas';
my $type = 'Char';
fill_table($file,$path,$delim,$head,$type);
|< 1 2 >| | 11 Einträge, 2 Seiten |