I have a script I'm writing for scheduling of employees. It generates a table displaying each hour of the day and marks the scheduled hours. This works with on employee. I need to know how to handle multiple inputs from the form with fields of the same name. The most I can figure is to use foreach with arrays. But I'm not sure how to orrganize it so that it works. In other words, it needs to print the values correctly in separate rows in the table. Here is my code so far.
Thanks.
I also think that my elsif statments could be shorter!

#!/usr/bin/perl -w ######################################## # Work Schedule Chart Generator Version 0.01 # By Nick Lafferty # ######################################## #use CGI::Carp qw(fatalsToBrowser); #warn "this is a complaint"; #die "But this is serious"; #use strict; use CGI qw/:standard/; print header; my ($employee, $date, $sshift, $eshift, $total_shift, $on_shift, $td, +$off_shift1, $off_shift2, $name); $date = param("date"); $employee = param("employee"); $sshift = param("sshift"); $eshift = param("eshift"); $name = "<TD>$employee</TD>"; # Calculate On shift hours and generate table cells $total_shift = $eshift - $sshift; $on_shift = "<TD>d</TD>" x $total_shift; # Calculate Off Shift hours and generate cells $td = "<TD></TD>"; if ($sshift eq "8"){ $off_shift1 = ""; }elsif ($sshift eq "9"){ $off_shift1 = "$td"; }elsif ($sshift eq "10"){ $off_shift1 = "$td$td"; }elsif ($sshift eq "11"){ $off_shift1 = "$td$td$td"; }elsif ($sshift eq "12"){ $off_shift1 = "$td$td$td$td"; }elsif ($sshift eq "13"){ $off_shift1 = "$td$td$td$td$td"; }elsif ($sshift eq "14"){ $off_shift1 = "$td$td$td$td$td$td"; }elsif ($sshift eq "15"){ $off_shift1 = "$td$td$td$td$td$td$td"; }elsif ($sshift eq "16"){ $off_shift1 = "$td$td$td$td$td$td$td$td"; }elsif ($sshift eq "17"){ $off_shift1 = "$td$td$td$td$td$td$td$td$td"; }elsif ($sshift eq "18"){ $off_shift1 = "$td$td$td$td$td$td$td$td$td$td"; }elsif ($sshift eq "19"){ $off_shift1 = "$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($sshift eq "20"){ $off_shift1 = "$td$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($sshift eq "21"){ $off_shift1 = "$td$td$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($sshift eq "22"){ $off_shift1 = "$td$td$td$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($sshift eq "23"){ $off_shift1 = "$td$td$td$td$td$td$td$td$td$td$td$td$td$td$td"; }else{ $off_shift1 = "$td$td$td$td$td$td$td$td$td$td$td$td$td$td$td$td"; } if ($eshift eq "8"){ $off_shift2 = "$td$td$td$td$td$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "9"){ $off_shift2 = "$td$td$td$td$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "10"){ $off_shift2 = "$td$td$td$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "11"){ $off_shift2 = "$td$td$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "12"){ $off_shift2 = "$td$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "13"){ $off_shift2 = "$td$td$td$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "14"){ $off_shift2 = "$td$td$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "15"){ $off_shift2 = "$td$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "16"){ $off_shift2 = "$td$td$td$td$td$td$td$td"; }elsif ($eshift eq "17"){ $off_shift2 = "$td$td$td$td$td$td$td"; }elsif ($eshift eq "18"){ $off_shift2 = "$td$td$td$td$td$td"; }elsif ($eshift eq "19"){ $off_shift2 = "$td$td$td$td$td"; }elsif ($eshift eq "20"){ $off_shift2 = "$td$td$td$td"; }elsif ($eshift eq "21"){ $off_shift2 = "$td$td$td"; }elsif ($eshift eq "22"){ $off_shift2 = "$td$td"; }elsif ($eshift eq "23"){ $off_shift2 = "$td"; }else{ $off_shift2 = ""; } $row = "$name$off_shift1$on_shift$off_shift2"; &table_header; sub table_header { print <<HTML; <HTML> <HEAD> <TITLE>b</TITLE> </HEAD> <BODY> <TABLE cols=18 width="95%" bgColor=#ccffff border=1> <CAPTION>$date</CAPTION> <TBODY> <TR vAlign=top> <TD vAlign=top>Name</TD> <TD vAlign=top>8:00</TD> <TD vAlign=top>9:00</TD> <TD vAlign=top>10:00</TD> <TD vAlign=top>11:00</TD> <TD vAlign=top>12:00</TD> <TD vAlign=top>1:00</TD> <TD vAlign=top>2:00</TD> <TD vAlign=top>3:00</TD> <TD vAlign=top>4:00</TD> <TD vAlign=top>5:00</TD> <TD vAlign=top>6:00</TD> <TD vAlign=top>7:00</TD> <TD vAlign=top>8:00</TD> <TD vAlign=top>9:00</TD> <TD vAlign=top>10:00</TD> <TD>11:00</TD> <TD>12:00</TD></TR> <TR>$row</TR> </BODY> </HTML> HTML }

In reply to Help With Multiple Form Fields by nlafferty

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.