summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travel/Status/DE')
-rw-r--r--lib/Travel/Status/DE/IRIS/Stations.pm.PL27
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/Travel/Status/DE/IRIS/Stations.pm.PL b/lib/Travel/Status/DE/IRIS/Stations.pm.PL
index b19043f..3547448 100644
--- a/lib/Travel/Status/DE/IRIS/Stations.pm.PL
+++ b/lib/Travel/Status/DE/IRIS/Stations.pm.PL
@@ -41,24 +41,18 @@ our $VERSION = '1.51';
my @stations = (
EOF
-for my $station (@{$stations}) {
- if ($station->{latlong}) {
+for my $station ( @{$stations} ) {
+ if ( $station->{latlong} ) {
$buf .= sprintf(
"['%s','%s',%s,%s,%s],\n",
- $station->{ds100},
- $station->{name},
- $station->{eva},
- $station->{latlong}[1],
+ $station->{ds100}, $station->{name},
+ $station->{eva}, $station->{latlong}[1],
$station->{latlong}[0],
);
}
else {
- $buf .= sprintf(
- "['%s','%s',%s],\n",
- $station->{ds100},
- $station->{name},
- $station->{eva}
- );
+ $buf .= sprintf( "['%s','%s',%s],\n",
+ $station->{ds100}, $station->{name}, $station->{eva} );
}
}
@@ -148,7 +142,12 @@ sub get_station_by_name {
my $min_dist = min(@distances);
my @station_map = pairwise { [ $a, $b ] } @stations, @distances;
- my @substring_matches = grep { $_->[1] =~ m{$name}i } @stations;
+ my @substring_matches;
+
+ # $name may be an invalid regular expression
+ eval { push(@substring_matches, grep { $_->[1] =~ m{\Q$name\E}i } @stations) };
+ eval { push(@substring_matches, grep { $_->[1] =~ m{$name}i } @stations) };
+
my @levenshtein_matches
= map { $_->[0] } grep { $_->[1] == $min_dist } @station_map;
@@ -297,4 +296,4 @@ station data used by this module is also available under a CC-BY 4.0 license on
L<http://data.deutschebahn.com/dataset/data-haltestellen>.
EOF
-write_file($ARGV[0], {binmode => ':utf8'}, $buf);
+write_file( $ARGV[0], { binmode => ':utf8' }, $buf );