Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Error while printing hash table

by Anonymous Monk
on Sep 18, 2012 at 09:07 UTC ( #994244=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi please find below for the code.I am taking a date and getting the next three dates.Also i am assigning all these to a hash table and printing it

use Data::Dumper; use Date::Simple; #initializing the variable $a[0]="2012-08-16"; $i=1; $dateplus=$a[0]; #Getting next 3 dates while($i<=3) { $dateplus = Date::Simple->new($dateplus); $dateplus++; $a[$i]=$dateplus; $i++; } #-----Saving the next week dates in a hash table---------- %datesofnextWeek_var1 = ( "1" => ["Sunday",$a[0]], "2" => ["Monday",$a[1]], "3" => ["Tuesday",$a[2]], "4" => ["Wednesday",$a[3]], ); print Dumper %datesofnextWeek_var1; @test=@{$datesofnextWeek_var1{2}}; print $test[1];

For print Dumper %datesofnextWeek_var1; m getting $a1,$a2 etc as bless( do{\(my $o = 15570)}, 'Date::Simple' ) but $a[0] is coming properly. Also from hashtable if m taking values i wil get it properly.Thr problem is while printing the entire hashtable.Please help.If you have any confusion in my question u can run the above mentioned code.Then it will be clear

Replies are listed 'Best First'.
Re: Error while printing hash table
by davido (Archbishop) on Sep 18, 2012 at 09:22 UTC

    Date::Simple->new() returns an object (a blessed reference). That object has overloaded mathematical operators, which is why you can use numerical operators on it. But if you want to print it, you need to use an accessor that stringifies it meaningfully, such as via the as_d8, as_iso, or as_string. You can even interpolate the object into a string. But your usage isn't doing that.

    You've got to read a module's POD if you want to understand how to use it.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994244]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-01-21 12:06 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (184 votes). Check out past polls.