Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Possible Bug?

by dru145 (Friar)
on Apr 16, 2002 at 20:32 UTC ( [id://159617]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: DBI script runs from command line, not from CGI
in thread DBI script runs from command line, not from CGI

tachyon and fellow monks,

I took out ENCTYPE, and it still did not work. I know my file arrived ok, because I tested it with this code:
while(<$infile>){ push (@line, $_); }
When I print out @lines, it prints out the file I just uploaded. Also, this bit of error checking seems to work
my $infile = upload ('file') or die "File was not uploaded correctly\n +";
because if I don't enter a filename, I get the error "File was not uploaded correctly."

Next, I started looking at my hash. Now, here is the strange part. This code works fine:
for $i (keys %data) { push (@ips, $i); }
I can print out @ips in the results page, but then I tried this:
for $i (keys %data) { push (@ips, $i); for $j (keys %{$data{$i}{ports}}) { push (@names, $data{$i}{cname}); } }
and @names would not print out. I also tried this:
for $i (keys %data) { for $j (keys %{$data{$i}{ports}}) { push (@ips, $i); } }
and now @ips does not print out. I tried the last two bits of code in a non-CGI script, and they both print out as expected. Do you think I stumbled on a possible bug? I would appreciate any suggestion since this is driving me crazy.

Thanks,
Dru
Another satisfied monk.

Replies are listed 'Best First'.
Re: Possible Bug?
by tachyon (Chancellor) on Apr 16, 2002 at 21:32 UTC

    No bug, just a simple coding error :-) If you used better varnames than $i and $j it would be more obvious. Just a thought.

    for $i (keys %data) { push (@ips, $i); for $j (keys %{$data{$i}{ports}}) { # push (@names, $data{$i}{cname}); # <--wrong push (@names, $data{$i}{$j}{cname}); } } # compare that with this code that uses logical names # if also uses my to localise variable scope, strict compliant too for my $ip (keys %data) { push @ips, $ip; for my $port ( keys %{$data{$ip}->{ports}} ) { push @names, $data{$ip}->{$port}->{cname}; } }

    I recommend that you add this code to check your data structure after you build %data from the file (if you were using CGI::Simple you could just call the dump() method :-) but anyway:

    # make %data require Data::Dumper; print $q->header; print $q->escapeHTML(Dumper(\%data)); exit;

    This will tell you if you have the correct data structure. I will tell you now with your current code you won't. I suspect there may be some serious logic errors in it. If you post a sample of the file I'll give you a hand to parse it into a logical data structure.

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-18 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found