CGI.PM Very very simple question

A

AMT2K5

Here is a subroutine I am working with that recieves an array full
results found of mp3s from an earlier readdir routine.

All I want wish to do is put every song in the array into its own <td>
as well as store the track name in a variable for further processing. I
am stuck at the Td function call.



sub mp3_form{
my $name;

$cgi->b("Your search produced:"),
$cgi->table({-border=>'1'},
$cgi->Tr({-align=>'center'},
$cgi->td(@_), )
)

}
 
J

John Bokma

AMT2K5 said:
Here is a subroutine I am working with that recieves an array full
results found of mp3s from an earlier readdir routine.

All I want wish to do is put every song in the array into its own <td>
as well as store the track name in a variable for further processing. I
am stuck at the Td function call.



sub mp3_form{
my $name;

$cgi->b("Your search produced:"),

^ you're sure about that , here?
$cgi->table({-border=>'1'},
$cgi->Tr({-align=>'center'},
$cgi->td(@_), )
)

Line the above out (maybe your client did it, but otherwise):

$cgi->table(

{ -border=>'1' },

$cgi->Tr(

{ -align=>'center' },
$cgi->td(@_),
)
)

"If you give them an argument consisting of a reference to a list, the
tag
will be distributed across each element of the list."
( THE DISTRIBUTIVE PROPERTY OF HTML SHORTCUTS, CGI.pm documentation)

use strict;
use warnings;

use CGI;

mp3_form( new CGI, 'a' .. 'z' );


sub mp3_form {

my $cgi = shift;

my @tds;
push @tds, $cgi->td( $_ ) for @_;

print
$cgi->b( "Your search produced:" ),

$cgi->table( { -border => 1 },

$cgi->Tr( { -align => 'center' }, \@tds )
);
}

Does the trick.
 
A

AMT2K5

Appreciate the help, I get the error message with the posted code
Can't call method "td" without a package or object reference at
results.cgi line 94.
 
B

Brian McCauley

AMT2K5 said:
Appreciate the help, I get the error message with the posted code
Can't call method "td" without a package or object reference at
results.cgi line 94.

Please quote sufficient context to make your reponses make sense.

I'm guessing that's the line with

$cgi->td

So, what did you do to put any value in $cgi?

Please produce a _minimal_ but _complete_ script that illustrates your
problem. (This and much other helpful advice can be found in the
posting guidelines).
 

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