Y'know, it's really, really nice to post actually parsable example code.

You could just seperate the first td call.

# corrected original my ($value1, $value2, $value3) = (1..3); print $cgi->Tr({ -align=>'LEFT', -valign=>'TOP'}, [ td( { -OnClick=>"javascript:dothis()" }, [ $cgi->a( {-href=>"http://example.com", -target=>"_new"}, $cg +i->img('blah.gif')) . $cgi->a( {-href => 'http://example.com' }, $value1 ). +"\n", $cgi->hidden( -name=>'name2', -value=>"$value2" ). $cgi->a( {-href => 'http://example.com' }, $value2 ) . + "\n", $cgi->hidden( -name=>'name3', -value=>"$value3" ). $cgi->a( {-href => 'http://example.com' }, $value3 ) . + "\n", ]), ]); print "\n"; # td call separated print $cgi->Tr({ -align=>'LEFT', -valign=>'TOP'}, td($cgi->a( {-href=>"http://example.com", -target=>"_new"}, $cgi-> +img('blah.gif')) . $cgi->a( {-href => 'http://example.com' }, $value1 )) +. "\n" . td( { -OnClick=>"javascript:dothis()" }, [ $cgi->hidden( -name=>'name2', -value=>"$value2" ). $cgi->a( {-href => 'http://example.com' }, $value2 ) . + "\n", $cgi->hidden( -name=>'name3', -value=>"$value3" ). $cgi->a( {-href => 'http://example.com' }, $value3 ) . + "\n", ]), );

But since this isn't obviously in a loop, you've got no reason to print your hidden fields within the table; that's just making the code messy. To make things a little saner, store things in advance in a list (for order) and a hash (for name-value association) and built it with a loop.

my @names = (qw(name1 name2 name3)); my %cells = (name1 => {href => 'http://example.com/1', value => $value +1}, name2 => {href => 'http://example.com/2', value => $value +2}, name3 => {href => 'http://example.com/3', value => $value +3}); sub row { my ($names, $cells) = @_; my $first = shift @$names; my @result; push @result, CGI::td(CGI::a({-href=> $cells->{$first}{href}, -targe +t => "_new"}, CGI::img('blah.gif')) . CGI::a({-href=> $cells->{$first}{href}}, $cel +ls->{$first}{value})); for my $name (@$names) { push @result, CGI::td({ -OnClick=>"javascript:dothis()" }, CGI::hidden(-name => '$name', -value => $cel +ls->{$name}{value}) . CGI::a({-href => $cells->{$name}{href}}, $ce +lls->{$name}{value})); } return join '', @result; } print $cgi->Tr({ -align=>'LEFT', -valign=>'TOP'}, row(\@names, \%cells +));

Then chuck that too and start using a template module.


In reply to Re: Creating a table using cgi.pm - a unique problem by Zed_Lopez
in thread Creating a table using cgi.pm - a unique problem by sara2005

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.