我写这个小程序来匹配模式和替代它:错误模式识别与字符串匹配的Perl程序
#!/usr/bin/perl
$LOGFILE = "odds.dat";
open(LOGFILE) or die("Could not open log file.");
foreach $line (<LOGFILE>) {
($hour, $match, $odd1, $oddx, $odd2, $dummy) = split(/\,/,$line);
($hteam,$ateam) = split(/ § /,$match);
$hteam=get_name($hteam);
$ateam=get_name($ateam);
$match="$hteam - $ateam";
$foo=qq("$hour" "$match" $odd1 $oddx $odd2 \n) ;
print $foo;
}
sub get_name {
# Return the full name for the team, if it exists, otherwise return the original
my %alias = (
"Atletico-MG" => "Atletico Mineiro",
"Atletico-PR" => "Atletico Paranaense",
...
...
"U.A.N.L.- Tigres" => "U.A.N.L.",
...
...
);
return $alias{$_[0]} // $_[0];
}
其中odds.dat是:
2011-10-28 20:00 , Atletico-MG § Atletico-PR ,2.00 ,5.00, 6.00
2011-10-28 20:00 ,U.A.N.L.- Tigres § Atletico-MG ,2.00,5.00,6.00
但输出是:
"2011-10-28 21:15 " " Atletico-MG - Atletico-PR " 2.00 5.00 6.00
"2011-10-28" "U.A.N.L. - Atletico-MG " 2.00 5.00 6.00
为什么Atletico-MG和Atletico-PR不被识别?