[Columbus-pm] weird datetime / push behavior

Smith,Devon smithde at oclc.org
Tue May 18 13:07:02 PDT 2010


It adds the fist and only DateTime object. Dumper is showing that all
successive additions are in fact references to that first object. You
might want to create a new object for each iteration, depending on
actual needs.

/dev

-- 
Devon Smith
Consulting Software Engineer
OCLC Research
http://www.oclc.org/research/people/smith.htm


-----Original Message-----
From: columbus-pm-bounces+smithde=oclc.org at pm.org
[mailto:columbus-pm-bounces+smithde=oclc.org at pm.org] On Behalf Of
Jonathan Hogue
Sent: Tuesday, May 18, 2010 3:52 PM
To: columbus-pm
Subject: [Columbus-pm] weird datetime / push behavior

see this sample script.

use strict;
use DateTime;
use Data::Dumper;

my $d = DateTime->now;

my @days;
foreach my $i ( 1..7 )
{
    push( @days, $d );
    $d->add( 'days' => 1);
}

print Dumper \@days;

It adds the first datetime object... but isn't doing what you expect
for the next iterations... what's going on here?

$VAR1 = [
          bless( {
  .....
                 }, 'DateTime' ),
          $VAR1->[0],
          $VAR1->[0],
          $VAR1->[0],
          $VAR1->[0],
          $VAR1->[0],
          $VAR1->[0]
        ];
_______________________________________________
Columbus-pm mailing list
http://columbus.pm.org/
Columbus-pm at pm.org
http://mail.pm.org/mailman/listinfo/columbus-pm




More information about the Columbus-pm mailing list