Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Parsing a Hash

by davorg (Chancellor)
on Jul 21, 2009 at 22:19 UTC ( #782106=note: print w/replies, xml ) Need Help??

in reply to Parsing a Hash

What does use warnings tell you?


See the Copyright notice on my home node.

Perl training courses

Replies are listed 'Best First'.
Re^2: Parsing a Hash
by northwestdev (Acolyte) on Jul 21, 2009 at 22:33 UTC
    I am not seeing any warnings at all. I get a blank page (except when I dump the hash, which I posted in another message on this thread, and that's the real dump of the hash, with no warnings). Here's the entire code:
    #!/usr/bin/perl use strict; use warnings; use Time::Local; use XML::DOM; use Net::Twitter; use Data::Dumper; use CGI; my $query = new CGI; print STDOUT $query->header; my $usename="myname"; my $pwd="mypwd"; my $twitterID="myname"; my $nt = Net::Twitter->new( traits => [qw/API::REST/], username => $usename, password => $pwd ); my $results = $nt->show_user($twitterID); #print Dumper $results; foreach my $user (@{ $results }) { my $id = $user->{id}; my $name = $user->{name}; print STDOUT $id." ".$name."<br>"; } print STDOUT $query->end_html;

      Well, I explained in the other thread what the problem is. The example code treats $results as an array ref but the show_user method returns a hash ref. You should get the (to my mind, really very clear) warning "Not an ARRAY reference".

      Which leaves us wondering why you're not seeing this warning when you clearly have use warnings in your code. My suspicion is that you're looking in the wrong place. All of the CGI scaffolding in your code makes me think that you're running this as a CGI program. Depending on which web server you're using and how it is configured several things can happen to warnings from CGI programs. The most common effect is that they are written to the web server error log. Did you look in there?

      You can force warnings and errors to be written to the browser by adding the following line to your code:

      use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

      But remember to remove it again before putting the program into production.

      It's also worth pointing out that just because your code is a CGI program, there's no reason why you shouldn't run it from your command line in order to try it out. I never put a CGI program onto a web server without running it from the command line first.


      See the Copyright notice on my home node.

      Perl training courses

        Thank you. Your post in the other thread, came a couple of hours after I started this one. I am running it as a CGI program. I have no access to the server error logs, so I will try forcing the fatal erros using CGI::Carp

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://782106]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2023-12-10 07:00 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (38 votes). Check out past polls.