Perl Script

object: to convert my personal movie list to HTML on the fly via CGI.

#! /usr/bin/perl -w

use 5.005
use CGI qw(:standard *table);

$TITLE = "Movie List";

print header, start_html($TITLE), h1($TITLE);

open (MOVIELIST, "/export/home/mydir/movie.list") || die "NO GO ($!)";


        print table({-border=>undef},
                Tr({-align=>CENTER,-valign=>TOP},
                [
                        th(['Title', 'Genre','Rateing','Time','Production Company']),

while (<MOVIELIST>) {
($TITLE,$GENRE,$RATEING,$TIME,$PROD_CO)=split(/:/, $_);
                        td(['$TITLE' , '$GENRE' , '$RATEING' , '$TIME' , '$PROD_CO']),
};
                ]
                )
        );

# EXAMPLE
#        print table({-border=>undef},
#                caption('When Should You Eat Your Vegetables?'),
#                Tr({-align=>CENTER,-valign=>TOP},
#                [
#                   th(['Vegetable', 'Breakfast','Lunch','Dinner']),
#                   td(['Tomatoes' , 'no', 'yes', 'yes']),
#                   td(['Broccoli' , 'no', 'no',  'yes']),
#                   td(['Onions'   , 'yes','yes', 'yes'])
#                ]
#                )
#             );

ERRORS:

syntax error at ./movie.cgi line 18, near "foreach "
syntax error at ./movie.cgi line 21, near "}"
Execution of ./movie.cgi aborted due to compilation errors.

SAMPLE movie.list:

Godfather I:Crime, Drama:R:175:Paramount
Godfather II:Crime:R:200:Paramount
Godfather III:Crime:R:161:Paramount
Young and Dangerous 1:Action, Adventure:IIB:99:Mei Ha Laser Disk Co
Young and Dangerous 2:Action, Adventure:IIB:99:Mei Ha Laser Disk Co
Young and Dangerous 3:Action, Adventure:II:98:Universe Laser & Video Co
Young and Dangerous 4:Action, Adventure:III:109:Mei Ha Laser Disk Co
Young and Dangerous 5:Action, Adventure:IIB:115:Universe Laser & Video Co
Young and Dangerous Prequel:Action, Adventure:III:115:Universe Laser & Video Co

1) I don't understand why the one error says:

syntax error at ./movie.cgi line 18, near "foreach "

since there is no "foreach" in your code, but I'm assuming it's referring to:

while (<MOVIELIST> ) {
($TITLE,$GENRE,$RATEING,$TIME,$PROD_CO)=split(/:/, $_);
                        td(['$TITLE' , '$GENRE' , '$RATEING' , '$TIME' , '$PROD_CO']),
};

since it's basically the same in functionality as a "foreach" loop.

2) I don't see anything wrong with the above part, except that I don't know if the parenthesis around <MOVIELIST> matter, since I've never used them. I've always coded:

while <MOVIELIST> {

Also, you may need to take that semicolon out which follows the bracket that closes the while loop.

while (<MOVIELIST> ) {
 ...
};   # this semicolon may be causing the error

3) I'm curious - lines such as:
td(['$TITLE' , '$GENRE' , '$RATEING' , '$TIME' , '$PROD_CO'])
are you passing these values to a function called td() ?

Why not just use:

print "<table border=0>
 <tr align=\"center\" valign=\"top\">
  <th>Title</th>
  <th>Genre</th>
  <th>Rating</th>
  <th>Time</th>
  <th>Production Company</th>
 </tr>";

while <MOVIELIST> {
 ($TITLE,$GENRE,$RATEING,$TIME,$PROD_CO)=split(/:/);
 print " <tr align=\"center\" valign=\"top\">
  <td>$TITLE</td><td>$GENRE</td><td>$RATEING</td><td>$TIME</td><td>$PROD_CO</td>
 </tr>";

print "</table>";

oombera: i want to use the shortcuts for html that are part of the CGI.pm module. td() = table data open and close.

The following script will take a list of movies from a file and sort them ALPHABETICLY then print them into a table on the web.

#! /usr/bin/perl -w

use CGI qw(:standard :html3);

print header, h4($PTITLE), start_html($PTITLE), hr;

$PTITLE = "Movie List";
$MOVIEFILE = "/export/home/mxdooley/movie/movie.list";

open (MOVIELIST, $MOVIEFILE) || bail ("cannot open $MOVIEFILE: $!");
@LIST=sort(<MOVIELIST>);

foreach (@LIST) {
        ($title, $genre, $rateing, $time, $prod_co) = split(/:/, $_);
                push(@TITLE,$title);
                push(@GENRE,$genre);
                push(@RATEING,$rateing);
                push(@TIME,$time);
                push(@PROD_CO,$prod_co);
                push(@COUNT,$#TITLE+1);
};

@AMOVIES = (\@TITLE, \@GENRE, \@RATEING, \@TIME, \@PROD_CO, \@COUNT);

@tmovie = (0 .. $#TITLE);
@headings = qw(# Title Genre Rateing Time Prod_Company);
@rows = th(\@headings);

foreach (@tmovie) {
push(@rows,td(["$AMOVIES[5][$_]","$AMOVIES[0][$_]","$AMOVIES[1][$_]","$AMOVIES[2][$_]","$AMOVIES[3][$_]","$AMOVIES[4][$_]"]));
};

print table({-border=>undef},
                Tr(\@rows)
);

print p(`date`);
print end_html;

sub bail {
        $error="@_";
        print h1("Unexpected Error"), p($error), end_html;
        die $error;
}

Oh, ok. Not that familiar with CGI.pm. That's a great feature; really makes the code look clean.