#!/usr/bin/perl -w ######################################################################## # # ######################################################################## # use strict; use DBI; use CGI qw/ :all /; use HTML::Template; # # Grab our template my $OLDIFS=$/; $/=undef; my $template=; $/=$OLDIFS; # # instantiate template object my $t = HTML::Template->new (scalarref => \$template , option => 'value' ); # # Connect to the database my $dbh = DBI->connect('DBI:Pg:database=trains;host=10.1.1.1', 'peter','$3cr3t') or die $DBI::errstr; # # Create a statement handle for our query my $sth=$dbh->prepare(qq( select train_number,leaves,arrives from train_info where leaves > current_time order by leaves limit 3 )) or die $dbh->errstr; # # Execute the query $sth->execute or die $sth->errstr; # # Process the results. my @train_list_ary = (); while (my $row=$sth->fetchrow_hashref) { push @train_list_ary,{ train_number => $row->{train_number}, leaves => $row->{leaves}, arrives => $row->{arrives} }; } # Store the parameter $t -> param( train_list => [ @train_list_ary ]); # # Start our engines.... print header,start_html,$t->output,end_html; exit(0); __END__
NumLv NYCArr LS