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

Another day...another problem with my output! I'm currently working on a set of code that reads input from db and generates a html page.
My Input is as follows:
ecmain109:ecmain:HP LaserJet 4050:ecserv1:Level I Support
ecmain112:ecmain:Epson 1500:none:Level II Support
ecmain144:ecmain:HP LaserJet 4050TN:ecserv1:Level I Support
ecmain145:ecmain:Lexmark 800:ecserv2:No Support
ecmain147:ecmain:HP LaserJet 8000:ecserv1:Level I Support
ecmain152:ecmain:HP LaserJet II:none:No Support
ecmain158:ecmain:HP LaserJet 4050N:ecserv2:Level I Support
ecmain159:ecmain:HP LaserJet 4MQ:ecserv1:Level I Support
ecgw110cp:Gateway:Tektronix 850:ecserv3:Level I Support
ecgw116:Gateway:HP LaserJet 4050N:ecserv3:Level I Support


Upon opening input I place data into hashes using the following code...

($name, $building, $type, $server, $support) = split ":",$_; $pserv{$name} = $server; $bldcnt{$building}++; $buildinghash{$building}{$name} = $type; $slevel{$name} = $support;

I am currently working on designing a table that contains the following:
Server name & number of Printers Room where located
Each printer-name attached to server

I am using foreach looping to generate the table but I continually receive output that contains one table row for each printer not one for each server. If anyone can give me some tips/pointers as to how I should set up the looping required I'd greatly appreciate it.

--Psychoto

Replies are listed 'Best First'.
Re: CGI-Output Problems
by tbo (Scribe) on Apr 18, 2002 at 02:16 UTC
    Hi, I'm not sure I've understand what are the datas (Is "room" the data $building ?). But, I hope the code below will help you. (I am sure this code can be improved). This code use CGI and the output is:
    ecserv1 ecmain
    ecmain109 :: HP LaserJet 4050 :: Level I Support
    ecmain144 :: HP LaserJet 4050TN :: Level I Support
    ecmain147 :: HP LaserJet 8000 :: Level I Support
    ecmain159 :: HP LaserJet 4MQ :: Level I Support

    ecserv2 ecmain
    ecmain145 :: Lexmark 800 :: No Support
    ecmain158 :: HP LaserJet 4050N :: Level I Support

    ecserv3 Gateway
    ecgw110cp :: Tektronix 850 :: Level I Support
    ecgw116 :: HP LaserJet 4050N :: Level I Support

    none ecmain
    ecmain112 :: Epson 1500 :: Level II Support
    ecmain152 :: HP LaserJet II :: No Support

    Code
Re: CGI-Output Problems
by chiller (Scribe) on Apr 18, 2002 at 04:42 UTC
    Can you post the code of your loop? This probably doesn't answer your question, but I don't understand exactly why you'd want to use hashes, if you can just pull the data right out of the database. If you want to do that (I assume you're using DBI), try something like this:
    ... $sth->execute; print "<table>"; while (my @row = $sth->fetcharray) { print <<END_OF_TEXT; <tr><td>$row[0], $row[1]</td><td>$row[1]</td></tr> <tr><td colspan="2">$row[3]</td></tr> END_OF_TEXT } print "</table>";
    ...where @row contains a row of your data. Of course if you just have a document delimited by :'s, you may just want to check out the Text::CSV_XS module.