Problems? Is your data what you think it is? | |
PerlMonks |
Re: Getting started with DateTimeby snax (Hermit) |
on Oct 15, 2017 at 16:07 UTC ( [id://1201402]=note: print w/replies, xml ) | Need Help?? |
Great stuff! It's a dozen plus years after this was written and it's still useful. There's a subtle bit introduced at the very end that should maybe be emphasized: these are DateTime objects we're dealing with, and the scalar variables are references to the underlying object, which can lead to some confusion if you let that fact slip your mind. Consider the bit about math with dates at the end:
Miss the ->clone bit and you've got two references to the same DateTime object, one week subtracted from the original $dt1 value. Probably not what you had in mind. Imagine expecting the following to DWIM:
See it? I've forgotten to clone my $start variable as I push it onto my stack. This code produces:
All I needed to do was push(@dates, $start->clone()); and then I see what I meant:
I hope this helps someone else avoid a similar problem in the future -- even a dozen years from now :)
In Section
Tutorials
|
|