foreach county

T

Todd Anderson

Dear Persons,
The code below doesn't work on some computers. The county list isn't
being displayed. I can't firgure out why it would on most computers but
not on some. I say computer because it's intermittent on the same browsers.
Any help is appreciated and thanks in advance.


sub Chooser_page {
if($name eq "Defaults"){ @counties = split (/\,/, $Defaults); }
if($name eq "Trustees"){ @counties = split (/\,/, $Trustees); }
if($name eq "Fsbos"){ @counties = split (/\,/, $Fsbos); }

&generic_header("Choose County");

&pagesetup;

print qq~
<table width="100%"><tr><td align="center">
<font id="font20">Choose a $name County</font>
<P>~;
foreach $county (@counties){
print qq~<a href="customerservice.cgi?$where=on&county=$county&session_key=$session_key&site_key=$site_key">$county<BR>~;
}
print qq~</td></tr></table>~;

&pageclose;

}# page
 
M

Martien Verbruggen

Dear Persons,
The code below doesn't work on some computers. The county list isn't
being displayed. I can't firgure out why it would on most computers but
not on some. I say computer because it's intermittent on the same browsers.
Any help is appreciated and thanks in advance.

What does "doesn't work" mean? Error messages? (If this runs as a CGI
program, check the error logs of the web server). Any warnings?

Are you using strict and warnings?

From your code example below, I'd wager a guess that you're not using
either.
sub Chooser_page {
if($name eq "Defaults"){ @counties = split (/\,/, $Defaults); }
if($name eq "Trustees"){ @counties = split (/\,/, $Trustees); }
if($name eq "Fsbos"){ @counties = split (/\,/, $Fsbos); }

No need to escape a comma in tregular expressions. It is not a special
character.
&generic_header("Choose County");

&pagesetup;

Don't call subroutines this way, unless you need to have the special
semantics that the leading ampersand impose. Read the perlsub
documentation to find out what that is.
print qq~
<table width="100%"><tr><td align="center">
<font id="font20">Choose a $name County</font>
<P>~;

Have you checked the output of this program to make sure things are in
there that you expect to be in there? Have you made sure that what
comes out is valid HTML? Don't just check with a browser. Inspect the
HTML outside of a browser.

Have you read the Perl FAQ, section 9?

Anyway, there is no way for us to even start debugging this. We have
no clue on what's in those variables, and we have no clue on how you
got here.

Write a small stand-alone program that uses strict and warnings, and
that has the problem you describe. Submit that to this newsgroup for
inspection.

Martien
 
M

Mark Hewitt

Todd Anderson said:
Dear Persons,
The code below doesn't work on some computers. The county list isn't
being displayed. I can't firgure out why it would on most computers but [snip]
sub Chooser_page {
if($name eq "Defaults"){ @counties = split (/\,/, $Defaults); }
if($name eq "Trustees"){ @counties = split (/\,/, $Trustees); }
if($name eq "Fsbos"){ @counties = split (/\,/, $Fsbos); }

And what if $name does not contain any of those three values you check for?
Then what will @counties contain? Same goes for $Defaults,$Trustees,$Fsbos
you sure they contain valid data?
Perhaps one of there have bad data in them, hence countries array is empty
and nothing get printed? (depending on what you mean by "doesn't work" of
course!)

Maybe put in some error checking, or default mechanism to fall back on if
$name does not contain what you except

Also, drop the \, you don't need to escape comma's in regular expressions,
more readable this way!
if ( $name eq "Defaults" ) { @counties = split ( /,/ , $Defaults ); }

[snip]

Thanks,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top