adding days to date

[email protected] ("jagdish eashwar")
Newsgroups perl.datetime
Message-ID <[email protected]>
Hi,

I came across some unexpected behaviour in datetime. In the following
script, I first define $date1. Then I set $day1 = $date1. Then I add 2 days
to $day1. Why does $date1 also get incremented?

#!/usr/bin/perl
use strict;
use warnings;

use DateTime;

my $date1 = DateTime->new(year => 2007,
             month => 12,
             day => 23);

my $day1 = $date1;

$day1->add(days => 2);

print "day1 = ",$day1,"\n";   # gives me 2007-12-25 correctly.
print "date1 = ",$date1,"\n";  # why does $date1 also change to 2007-12-25?


Jagdish Eashwar
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.