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

Kenneth Thompson kthompson at omnihotels.com
Mon Oct 24 13:25:27 PDT 2005


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 at pm.org [mailto:omaha-pm-bounces at pm.org] On Behalf
Of Jay Hannah
Sent: Monday, October 24, 2005 2:22 PM
To: class-date at lists.dlux.hu
Cc: omaha-pm at 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 at pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm



More information about the Omaha-pm mailing list