QuoteName1 2005 5 112 165 198 287 814.7 910
Name2, W. 2005 4 127 162 193 279 314 430
Name3 Vorname 2006 8 110 192 282 314.3 870
1 2 3 4 5 6 7 8 9 10 11
while (<RE>) { chomp; s/\s+/ /g; /[A-Za-z]*\,?\s?[A-Za-z]*\.? /; my @felder = split / /,$'; (my $str = $&) =~ s/\s+$//; unshift(@felder,$str); push(@daten,\@felder); } close RE;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use warnings; use strict; my $res = []; while(my $line = <DATA>){ chomp $line; $line =~ /^(.*)\s+(\d{4})\s+(.*)$/; # Name in $1, Jahr in $2 my @meta = split /\s+/, $3; # splitte den Rest push @$res, [$1, $2, @meta]; } foreach my $r(@$res){ printf "Name: %s, Jahr: %u, Monat: %u \n", $r->[0], $r->[1], $r->[2]; } __END__ Name1 2005 5 112 165 198 287 814.7 910 Name2, W. 2005 4 127 162 193 279 314 430 Name3 Vorname 2006 8 110 192 282 314.3 870
1 2 3 4 5 6 7 8 9 10 11 12
while(my $line = <DATA>) { chomp $line; my @data; if( @data = $line =~ /^(.*?)\s+(\d{4})\s*(.+?)\s*$/ and push(@data,split(/\s+/,pop(@data))) > 8 ) { push @$res, \@data; } else { warn(qq(line "$line" not martch!\n))} }
1
2
3
my ($name, $date, $rest) = split /\s+(\d+)\s+/;
my @rest = split ' ', $rest;
push @daten, [$name, $date, @rest];
1 2 3
my ($name, $date, $rest) = split /\s+(\d+)\s+/; my @rest = split ' ', $rest; push @daten, [$name, $date, @rest];
1 2 3 4 5 6 7 8 9 10
use Data::Dumper; while (<DATA>) { my ($name, $date, $rest) = split /\s+(\d{4})\s+/, $_, 3; my @rest = split ' ', $rest; print Dumper [$name, $date, @rest]; } __DATA__ Name1 2005 5 112 165 198 287 814.7 910 Name2, W. 2005 4 127 162 193 279 314 430 Name3 Vorname 2006 8 110 192 282 314.3 870
1 2
my ($name, $date, @rest) = split /\s+(\d+)\s+/; push @daten, [$name, $date, @rest];
2011-04-05T14:13:52 TaulmarillBist du dir sicher, dass der Code richtig funktioniert? "Name1" wird nämlich wegen der Ziffer nicht als Name erkannt. Soll das so sein?
QuoteSoll das so sein?
1 2 3 4 5 6 7 8 9 10
my @daten; while(my $line = <RE>) { chomp $line; $line =~ /^(.*?)\s+(\d{4})\s+(.*)$/; # Name in $1, Jahr in $2 my @meta = split /\s+/, $3; # splitte den Rest push @daten, [$1, $2, @meta]; } close RE; &rech(@daten); # zur Auswertung