Link to home
Start Free TrialLog in
Avatar of plennon
plennon

asked on

filtering data in cgi

if i had a data file with the following contents

DAY;YEAR;MONTH;DATE
MON;2003;APR;23
TUE;2002;MAY;13
WED;1999;SEPT;8
TUE;2003;OCT;15
SAT;2001;APR;30

how would i display only the records whose months are equal to APR

Avatar of inq123
inq123

Hi plennon,

Using the code I posted earlier and modifying it a bit (adding an if statement) to suit your new purpose:

# here print your heading, you already have the code
open(IN, "filename.dat");
$_ = <IN>; # get rid of first line
while(<IN>)
{
 if(/;APR;[^;]+$/i) # if the second last element delimited by ; is APR (/i means case-insensitive)
 {
   chomp; # get rid of \n at end
   s/;/<\/td><td>/g; # replace ; with "</td><td>"
   print "<tr><td>$_</td></tr>\n";
 }
}
# here you can end your <table> tag by printing </table>

Cheers!
Avatar of plennon

ASKER

what if i wanted to have 12 checkboxes one for each month and only display the records for the months that have been checked
ASKER CERTIFIED SOLUTION
Avatar of inq123
inq123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial