michellem has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I'm sure there is something really obvious I'm missing, or something stupid I'm doing (as usual), but I'm utterly stumped.

I have a pretty large complex perl-cgi project, and right now, I'm running into strange problems with references. I've got one particular script that just hangs, without throwing any errors in the error logs.

Here's the snippet that I've identified is the problem:

foreach my $record (@records) { foreach my $key (keys %$record) { print "$key:$record->{$key}"; print $q->br; } }

The array of hashes is originally gotten from a subroutine. If I just print the key, I don't get the strange hanging with no error. It just prints the keys, executes some more code like it's supposed to, and exits like it's supposed to. It also doesn't seem to want to let me use the reference in any if statements.

If I use the code:
foreach my $record (@records) { foreach my $key (keys %$record) { if ($record->{$key} =~ /client/) {print "this is a client" +; print $q->br;} } }
It hangs too. I'm just at my wits end with this. There is another piece of code too that seems to cause this behavior, it's more complicated, but it basically involves sending values to CGI parameters.

I can handle it when I get error messages - then I know what to look for. But hanging with no errors is driving me crazy.

This is perl 5.8.0, RH9, Apache, etc. I'm using strict and warnings. I also unbuffered stdout. Thanks!

Replies are listed 'Best First'.
Re: Problems with references?
by cLive ;-) (Prior) on Oct 07, 2003 at 05:51 UTC
    Have you dumped @record to see if it contains what you think it contains? That would be a good place to start:
    use Data::Dumper; # ... print Data::Dumper->Dumper(\@record);
    And are you *sure* it's hanging where you think it is? You only provide a snippet, so we'd be stabbing in the dark trying to guess why this seemingly innocent code snippet would hang.

    .02

    cLive ;-)

Re: Problems with references?
by davido (Cardinal) on Oct 07, 2003 at 05:54 UTC
    Maybe you should use Data::Dumper to get a look at the suspect, @records. The code you've shown above ought not be capable of hanging the system without emitting a warning, but nevertheless, it could be helpful to take a look and see if the contents of @records is what you expect it to be.


    Dave


    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein