Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

Comment on Error while printing hash table
Download Code
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.


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994244]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-12-21 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls