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

Jay Hannah jay at jays.net
Thu Nov 10 15:09:42 PST 2005


From: "Balázs Szabó (dLux)" [mailto:dlux at dlux.hu]
> use Class::Date qw(date);
> $a = date "2000-11-11";
> $b = date "1970-10-21";
>
> print "a: $a, b: $b\n";
> swap1($a, $b);
> print "a: $a, b: $b\n";
>
> sub swap1 {
>    $x = $_[0];
>    $_[0] = $_[1];
>    $_[1] = $x;
> }

Ahhh, yes. I misread your email the first time. To make sure I know 
what's happening let me walk through it...

> sub swap1 {

$a is obj in year 2000. $b is obj in year 1970. $_[0] is a ref to $a. 
$_[1] is a ref to $b.

>    $x = $_[0];

$x is created, a new obj in year 2000.  (via clone() inside Class::Date)

>    $_[0] = $_[1];

$a obj is destroyed. A new $a is created, year 1970.  (via clone() 
inside Class::Date)

>    $_[1] = $x;
> }

$b obj is destroyed. A new $b is created, year 2000.  (via clone() 
inside Class::Date)

Is that right?

Thanks,

j



More information about the Omaha-pm mailing list