kepler has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm trying to assign variables to a DateTime module like this:
$dt = DateTime->new( year => $year, month => $month, day => $day, hour => $hour, minute => $minutes, second => $seconds, );
which gives undef to all variables, although the values are not empty. Sorry to ask: but how do I do this right? Kind regards, Kepler

Replies are listed 'Best First'.
Re: Dumb question...probably...
by choroba (Cardinal) on Aug 20, 2014 at 19:17 UTC
    What do you mean by "the values"? It works for me:
    #!/usr/bin/perl use warnings; use strict; use DateTime; my $year = 2014; my $month = 8; my $day = 20; my $hour = 21; my $minutes = 13; my $seconds = 1; my $dt = 'DateTime'->new( year => $year, month => $month, day => $day, hour => $hour, minute => $minutes, second => $seconds, ); print "DT: $dt\nyear: $year\n"; __END__ Output: DT: 2014-08-20T21:13:01 year: 2014
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Dumb question...probably...
by fishmonger (Chaplain) on Aug 20, 2014 at 19:21 UTC

    Are you sure you're passing valid values for each of those parameters?

      Here's the code

      use DateTime; use DateTime::TimeZone; #For testing $zone = "America/Chicago"; $date = "8/5/1967"; $time = "8:30:00"; my $tz = DateTime::TimeZone->new( name => $zone ); ($day,$month,$year) =~ split(/\//,$date); ($hour,$minutes,$seconds) =~ split(/\:/,$time); my $dt = DateTime->new( year => $year, month => $month, day => $day, hour => $hour, minute => $minutes, second => $seconds, );
      What am I missing here...? Regards, Kepler
        ($hour,$minutes,$seconds) =~ split(/\:/,$time); print join "|", ($hour,$minutes,$seconds); -- ||

        "=~" ne "="; :P --> use strict; use warnings;

        Oh crap... the =~ in split... :/
          A reply falls below the community's threshold of quality. You may see it by logging in.