[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Class::Date - change once set



Hola --

Is there any way to change a Class::Date value once one has been set?
Right now my demo script is failing:

My script:

---
use Class::Date qw( date );

my $d1 = date "1970-01-01";
my $d2 = date "2000-01-01";

stuff($d1, $d2);
print "[$d1][$d2]\n";

sub stuff {
    my ($d1, $d2) = @_;
    if ($d2 > $d1) {
       $d1 = $d2;   # <---- I want to overwrite the existing $d1 here
    }
    print "[$d1][$d2]\n";
}
---

When I run it:

$ perl j.pl
[2000-01-01 00:00:00][2000-01-01 00:00:00]
[1970-01-01 00:00:00][2000-01-01 00:00:00]

$d1 is getting a NEW object, not overwriting the original $d1, so when
stuff() returns I have lost my change to $d1.

Is there any way to change $d1 inside stuff()? I tried clone() and set()
without any luck.

Thanks!

j