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

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



Well, it's clumsy but it works. Maybe it could be written into the class
as another clone option?

use Class::Date qw( date );

my $d1 = Class::Date->new("1971-01-01");
my $d2 = Class::Date->new("2000-01-01");

print "[$d1][$d2]\n";
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
       foreach my $idx (0 .. 9) {
         $d1->[$idx] = $d2->[$idx];
       }
    }
}
 

-----Original Message-----
From: omaha-pm-bounces@pm.org [mailto:omaha-pm-bounces@pm.org] On Behalf
Of Jay Hannah
Sent: Monday, October 24, 2005 2:22 PM
To: class-date@lists.dlux.hu
Cc: omaha-pm@pm.org
Subject: [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



_______________________________________________
Omaha-pm mailing list
Omaha-pm@pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm