Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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

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.


    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?
[erix]: then you might as well send that patch to the DBIC guys :)
[Corion]: erix: Yeah, I just found that it has no documentation at all on how to circumvent/ eliminate "1+n SELECTs" by building a local hash... I guess I have to make ->has_many do the hash lookup instead of doing the SQL query. But as the problem ...
[Corion]: ... has only manifested itself so far through the puzzled questions of other bystanders, I won't go deeper at this time. But the DBIx::Class documentation could well do with a document on how to make "it" (that is, ORMs in general) faster ;)
[Corion]: I find that DBIx::Class, like most ORMs makes things easy until they become performance critical and then makes it horribly hard to change things because the design is highly inflexible if you don't already know about the problems of 1+n :-/
[choroba]: that's why I don't like similar libraries. They pretend you don't have to learn SQL, but in the end, you have to learn how SQL plus to overcome their own limitations
[Corion]: "Just write the proper SQL beforehand" is of course the appropriate solution, but if you did that, you wouldn't/couldn't use DBIx::Class either. At least not in an obvious (to me) way.
choroba scratches a "how"
[Corion]: choroba: Exactly... But maybe that's just because I'm old and grumpy ;)
[Corion]: But maybe that could also be a nice talk, how to restructure your DBIx::Class-based app to remove 1+n-style query patterns

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2017-09-25 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (279 votes). Check out past polls.

    Notices?