Subject: | Thrashing of $_ |
Hi Steven,
DateTime-Format-Natural 0.64 can sometimes thrash $_. Here's an example
of why that's bad:
use DateTime::Format::Natural;
my @unparsed = qw/12-28-07 12-29-07/;
my %parsed;
for (@unparsed) {
my $dtfn = DateTime::Format::Natural->new;
my $dt = $dtfn->parse_datetime($_);
$parsed{$_} = $dt->ymd;
}
use Data::Dumper;
print Dumper \%parsed; # '/' => 2007-12-28
print @unparsed; # //
Attached is a patch that fixes this. I had fun tracking it down. :)
Shawn
Subject: | dollar-underscore.diff |
--- lib/DateTime/Format/Natural.pm 2007-12-28 11:52:32.000000000 -0500
+++ lib/DateTime/Format/Natural-new.pm 2007-12-28 11:52:25.000000000 -0500
@@ -104,7 +104,7 @@
$format = join $separator, ($length{4} == 0 ? qw(yyyy mm dd) : qw(dd mm yyyy));
}
else {
- $separator = do { $_ = $format;
+ $separator = do { local $_ = $format;
tr/a-zA-Z//d;
tr/a-zA-Z//cs;
quotemeta; };