Thread Namen aus String extrahieren
(11 answers)
Opened by hugenyn at 2011-04-05 12:50
Angenommen, das Jahr ist immer vierstellig:
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 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 Rolf |