Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
and call it so in another package:sub foo { my ($self,$input) = @_; my @ymd = split("-",$input); my $date = { day => $ymd[2], month => $ymd[1], year => $ymd[0], }; my $dt = eval{DateTime->new($date)}; return unless $dt; $date->{dt} = $dt; print "date: ".dump($date)."\n"; return $date; }
my $result = $date_thingy->foo("2000-01-01");
Amazingly, dump outputs all as expected ( hash with year,month,day set to the expected values, and datetime with expected values ). But $result is undef in the calling function. How could that possibly happen?
$date_thingy exists btw, after and before the call.
using perl 5.18.2
This is driving me insane, and no, there is absolutely no further line between print and return, and removing the print changes nothing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hashref return fails
by choroba (Cardinal) on May 27, 2015 at 21:53 UTC | |
|
Re: hashref return fails
by Anonymous Monk on May 27, 2015 at 21:59 UTC | |
by FloydATC (Deacon) on May 28, 2015 at 13:27 UTC | |
by Anonymous Monk on May 28, 2015 at 14:03 UTC | |
|
Re: hashref return fails
by Anonymous Monk on May 28, 2015 at 15:25 UTC |