You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by "Philip M. Gollucci" <ph...@p6m7g8.com> on 2003/02/19 11:58:30 UTC

Re: output table with variable data

First of all, you probably want to pass the array by reference, but I think 
you want a hash reference in reality.

aka
print &interface_list(\%interfacelist);

next you actually need to assign it to a local var in the function.
Third, use CGI.pm or some sub class for the love of god.
Next your don't look like your using (use strict;) you probably should.
Finally, maybe a hash reference instead of an array reference.

use strict;
use CGI::Pretty qw (:standard);
my $query = CGI->new();

sub interface_list (\%) {

  my ($interfacelist_href) = @_;
  my $str = "";

  my @headings = qw (Mon Device Interface Speed Line);
  $str .= Tr({-class=>'heading'}, td({}, \@headings));

   foreach my $key (sort keys %$interfacelist_href) {
     my $item = $interfacelist_href->{$key};
      $str .= Tr(
                    {-class=>'light'}, 
                    td({-class=>$item->{'property_0'}}, ["<a>" . 
$item->{'property_1} . "</a>"]),
                   etc........
                   );
    }

  return $str;
}


On Wednesday 19 February 2003 13:45, Alexander Hartmaier wrote:
> Hi list!
>
> I have to output a html table in some of my embperl pages which always
> looks the same but the data is slightly different.
> My approch was to write a small sub which takes the array with the data and
> looks like this:
>
> ---------------------------------------------------------------------------
>----------------------------------------------------------------------------
>--------------------- sub interface_list (@interfacelist)
> {
>   print ("
>   <tr class=heading>
>     <td>Mon</td>
>     <td>Device</td>
>     <td>Interface</td>
>     <td>Speed</td>
>     <td>Line</td>
>   </tr>
>   ");
>   for $indx ( 0 .. $#interfacelist )
>   {
>     print ("
>     <tr class=light>
>       <td class= $interfacelist[$indx][0] ><a> $interfacelist[$indx][1]
> </a></td>
>       <td><a href='view-device.epl?id_device=$interfacelist[$indx][2] '>
> $interfacelist[$indx][3] </a></td>
>       <td><a href='view-interface.epl?id_interface=
> $interfacelist[$indx][4] '> $interfacelist[$indx][5] </a></td>
>       <td><a href='view-line.epl?id_line= $interfacelist[$indx][6] '>
> $interfacelist[$indx][7] </a></td>
>     </tr>
>     ");
>   };
> }
> ---------------------------------------------------------------------------
>----------------------------------------------------------------------------
>---------------------
>
> My problem is that when I call the sub with '[+ interface_list
> (@interfacegrp) +]' the lines are appended to the end of the output instead
> of the line where I call it!
> Furthermore the array @interfacelist is empty...
>
> I think there is a better way to handle this problem!
> Gerald or anybody else has an idea?
>
> THX Alex
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

-- 
END 
------------------------------------------------------------------------------ 
Philip M. Gollucci philip@p6m7g8.com 301.474.9294 301.646.3011 (cell) 

Science, Discovery, & the Universe (UMCP) 
Webmaster & Webship Teacher 
URL: http://www.sdu.umd.edu 

eJournalPress 
Database/PERL Programmer & System Admin 
URL : http://www.ejournalpress.com 

Resume : http://p6m7g8.net/Resume 


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org