Skip Menu |

This queue is for tickets about the Date-Manip CPAN distribution.

Report information
The Basics
Id: 66253
Status: resolved
Priority: 0/
Queue: Date-Manip

People
Owner: Nobody in particular
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 6.21
Fixed in: (no value)



Subject: ParseDate alters its argument if arrayref
If (by mistake or confusion) you pass an array reference to ParseDate, it goes inside the array and deletes one of the elements or otherwise changes it. I would expect it to throw an error if given a reference instead of a string to parse, but if passing references is allowed, they should be treated as read-only and the data structure pointed to should not be altered. perl -MDate::Manip -MData::Dumper -E '$x = [ "2011-02-25" ]; ParseDate $x; say Dumper $x'
The documentation for ParseDate clearly explains the behavior (and even the historical reason for it). From the docs for ParseDate: === This takes an array or a string containing a date and parses it. When the date is included as an array (for example, the arguments to a program) the array should contain a valid date in the first one or more elements (elements after a valid date are ignored). Elements containing a valid date are shifted from the array. The largest possible number of elements which can be correctly interpreted as a valid date are always used. If a string is entered rather than an array, that string is tested for a valid date. The string is unmodified, even if passed in by reference. === Given that this behavior is the original behavior and dates back more than 15 years, I'm not going to change it at this point. I realize that this may feel unintuitive to some, but it's actually a feature that has some good uses. And it's easy to check whether the entire arrary was parsed by looking to see if it's empty after the call.