bazz
08-13-2005, 04:13 PM
Yes, I thought I could count but this particular count is troubling me immensely!
I would appreciate any pointers you may have rather than chunks of code because I want to learn. After posting this, it seems that it may actually be a conditional problem. So whichever it may be, Your advice is sought.
My perl runs a loop and where a name (in an array), occurs more than once, it is only outputted once to html.
The number of <ul> and <li> added at the end of each loop matters and it is for this that I need to fix this.
The page is here (http://demodirectory.thechrissystem.com/cgi-bin/dropdown_test), (on-going project) and the code is here
my $countBusinessType = 0;
my $countBusinessCounty = 0;
my $countBusinessCat = 0;
my $countBusinessLocalRegion = 0;
my $countBusinessSubType = 0;
my $countBusinessName = 0;
foreach my $fileName ( @listOfDirs ) {
chomp;
my ($businessType, $businessCounty, $businessCat, $businessLocalRegion, $businessSubType, $businessName, $grid) = split /_/, $fileName, 7;
#my $Filename = join'_', $businessType, $businessCounty, $businessLocalRegion, $businessType, $businessName, $grid;
if ( $businessType ne $typeGroup ) {
if ( $typeGroup ne '' ) { # ugly hack (better with hash arrays)
}
$countBusinessType++;
$typeGroup = $businessType;
print <<EOF;
<li><a href="#">$businessType</a><ul>
EOF
} # end of if businessTypeGroup
if ( $businessCounty ne $countyGroup ) {
if ( $countyGroup ne '' ) {
}
$countyGroup = $businessCounty;
$countBusinessCounty++;
print <<EOF;
<li><a href="#">$businessCounty</a><ul>
EOF
} # end of if businessCounty
if ( $businessCat ne $catGroup ) {
if ( $catGroup ne '' ) { # ugly hack (better with hash arrays)
}
$countBusinessCat++;
$catGroup = $businessCat;
print <<EOF;
<li><a href="#">$businessCat</a><ul>
EOF
} # end of if businessCat
if ( $businessLocalRegion ne $localRegionGroup ) {
if ( $businessLocalRegion ne '' ) { # ugly hack (better with hash arrays)
}
$countBusinessLocalRegion++;
$localRegionGroup = $businessLocalRegion;
print <<EOF;
<li><a href="#">$businessLocalRegion</a><ul>
EOF
} # end of if businessLocalregion
if ( $businessSubType ne $subTypeGroup ) {
if ( $subTypeGroup ne '' ) { # ugly hack (better with hash arrays)
}
$countBusinessSubType++;
$subTypeGroup = $businessSubType;
print <<EOF;
<li><a href="#">$businessSubType</a><ul>
EOF
} # end of if businessSubType
if ( $businessName ne $nameGroup ) {
if ( $nameGroup ne '' ) { # ugly hack (better with hash arrays)
}
$nameGroup = $businessName;
$countBusinessName++;
print <<EOF;
<li><a href="#">$businessName</a></li></ul>
EOF
print <<EOF;
numbers of counts at loop end<br />
countBusinessType = $countBusinessType<br />
countBusinessCounty = $countBusinessCounty<br />
countBusinessCat = $countBusinessCat<br />
countBusinessSubType = $countBusinessSubType<br />
countBusinessLocalRegion = $countBusinessLocalRegion<br />
countBusinesName = $countBusinessName<br />
EOF
} # end of foreach fileName
I would appreciate any pointers you may have rather than chunks of code because I want to learn. After posting this, it seems that it may actually be a conditional problem. So whichever it may be, Your advice is sought.
My perl runs a loop and where a name (in an array), occurs more than once, it is only outputted once to html.
The number of <ul> and <li> added at the end of each loop matters and it is for this that I need to fix this.
The page is here (http://demodirectory.thechrissystem.com/cgi-bin/dropdown_test), (on-going project) and the code is here
my $countBusinessType = 0;
my $countBusinessCounty = 0;
my $countBusinessCat = 0;
my $countBusinessLocalRegion = 0;
my $countBusinessSubType = 0;
my $countBusinessName = 0;
foreach my $fileName ( @listOfDirs ) {
chomp;
my ($businessType, $businessCounty, $businessCat, $businessLocalRegion, $businessSubType, $businessName, $grid) = split /_/, $fileName, 7;
#my $Filename = join'_', $businessType, $businessCounty, $businessLocalRegion, $businessType, $businessName, $grid;
if ( $businessType ne $typeGroup ) {
if ( $typeGroup ne '' ) { # ugly hack (better with hash arrays)
}
$countBusinessType++;
$typeGroup = $businessType;
print <<EOF;
<li><a href="#">$businessType</a><ul>
EOF
} # end of if businessTypeGroup
if ( $businessCounty ne $countyGroup ) {
if ( $countyGroup ne '' ) {
}
$countyGroup = $businessCounty;
$countBusinessCounty++;
print <<EOF;
<li><a href="#">$businessCounty</a><ul>
EOF
} # end of if businessCounty
if ( $businessCat ne $catGroup ) {
if ( $catGroup ne '' ) { # ugly hack (better with hash arrays)
}
$countBusinessCat++;
$catGroup = $businessCat;
print <<EOF;
<li><a href="#">$businessCat</a><ul>
EOF
} # end of if businessCat
if ( $businessLocalRegion ne $localRegionGroup ) {
if ( $businessLocalRegion ne '' ) { # ugly hack (better with hash arrays)
}
$countBusinessLocalRegion++;
$localRegionGroup = $businessLocalRegion;
print <<EOF;
<li><a href="#">$businessLocalRegion</a><ul>
EOF
} # end of if businessLocalregion
if ( $businessSubType ne $subTypeGroup ) {
if ( $subTypeGroup ne '' ) { # ugly hack (better with hash arrays)
}
$countBusinessSubType++;
$subTypeGroup = $businessSubType;
print <<EOF;
<li><a href="#">$businessSubType</a><ul>
EOF
} # end of if businessSubType
if ( $businessName ne $nameGroup ) {
if ( $nameGroup ne '' ) { # ugly hack (better with hash arrays)
}
$nameGroup = $businessName;
$countBusinessName++;
print <<EOF;
<li><a href="#">$businessName</a></li></ul>
EOF
print <<EOF;
numbers of counts at loop end<br />
countBusinessType = $countBusinessType<br />
countBusinessCounty = $countBusinessCounty<br />
countBusinessCat = $countBusinessCat<br />
countBusinessSubType = $countBusinessSubType<br />
countBusinessLocalRegion = $countBusinessLocalRegion<br />
countBusinesName = $countBusinessName<br />
EOF
} # end of foreach fileName