use strict; use warnings; use CGI; use List::Util qw(max); use lib "C:/Documents and Settings/Dawn/My Documents/fantasy/files/perl/lib"; use Base::HTML qw(start_html end_html line); use Base::GetDir qw(data_directory); use Base::CSV::Hash qw(get_hash); my %movies; my %movies_data = ( 'csv' => data_directory("Movies")."movies.csv", 'headings' => [qw(id title first_year last_year wiki amg imdb tvcom flixster genre theme type own)], ); get_hash(\%movies,\%movies_data); my %text_inputs = ( general => [qw(id title first_year last_year genre theme)], external_links => [qw(wiki amg imdb tvcom flixster)], ); my %radio_lists = ( type => [qw(film miniseries television_program)], own => [qw(blue-ray dvd vhs)], ); sub title_length { my @lengths; for my $movie (keys %movies) { push @lengths, length($movies{$movie}{title}); } my $length = max(@lengths); return $length; } start_html('','','no'); line(3,qq(
)); for my $movie (sort keys %movies) { my $length = title_length(); my $title = $movies{$movie}{title} ? $movies{$movie}{title} : $movies{$movie}{id}; line(4,qq(

$title

)); line(4,qq(
)); for my $group (keys %text_inputs) { my $legend = ucfirst $group; $legend =~ s!_! !g; line(5,qq(
)); line(6,qq($legend)); for my $heading (@{$text_inputs{$group}}) { my $print_heading = $heading; $print_heading =~ s!_! !; my $label_id = $movies{$movie}{id}.'_'.$heading; $label_id =~ s! !_!g; line(6,qq(
)); line(7,qq()); line(7,qq()); line(6,qq(
)); } line(5,qq(
)); } line(5,qq(
)); for my $key (keys %radio_lists) { line(6,qq(
)); line(7,qq($key)); for my $type (@{$radio_lists{$key}}) { my $checked = ""; #The following commented out code causes the script to hang up in my browser. It is supposed to print " checked" on the radio button with the same value as the movie has if any. # if ($movies{$movie}{$key} eq $type) { # $checked = " checked"; # } my $print_heading = $type; $print_heading =~ s!_! !; my $label_id = $movies{$movie}{id}.'_'.$type; $label_id =~ s! !_!g; line(7,qq(
)); line(8,qq()); line(8,qq()); line(7,qq(
)); line(6,qq(
)); } line(5,qq(
)); line(4,qq(
)); } line(4,qq(
)); line(3,qq(
)); end_html(); #### sub tab { my ($var) = @_; return ("\t") x $var; } sub line { my ($tab,$var) = @_; print tab($tab).$var."\n"; } #### package Base::CSV::Hash; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = qw(get_hash); sub open_file { my ($file) = @_; open(my $fh, $file) or die("can't open $file $!"); my @lines = <$fh>; chomp(@lines); return @lines; } sub get_hash { my ($hash,$data_hash) = @_; my @data = open_file($data_hash->{csv}); for my $value (@data) { my @inner_array = split(/\|/,$value); my $n = 0; for my $heading (@{$data_hash->{headings}}) { $$hash{$inner_array[0]}{$heading} = $inner_array[$n]; ++$n; } } } 1;