if statements - selection please use speaker notes for additional information!
TRANSCRIPT
![Page 1: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/1.jpg)
IF statements - selection
Please use speaker notes for additional information!
![Page 2: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/2.jpg)
![Page 3: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/3.jpg)
Record shown being processed on previous slide.
The divider is ,space.
![Page 4: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/4.jpg)
<!payroll.html><html><head><title>Mailing List</title></head><body><h1>Mailing List</h1><form action="http://www.pgrocer.com/cgi-bin/data/payroll.cgi" method=post>Enter Name:<br><input type=text name=name size=25><br><br>Enter Address:<br><input type=text name=stadr size=25><br><br>Enter City:<br><input type=text name=city size=20><br><br>Enter State:<br><input type=text name=state size=2<br><br>Enter ZIP:<input type=text name=zip size=10<br><br>Enter Job Type (S for Salaried, F for Full Time Hourly, P for Part Time Hourly):<input type=text name=jobtype size=2><br><br>Enter Job Code:<input type=text name=jobcode size=2><br><br>Enter Pay Per Hour:<input type=text name=payperhr size=10>or Enter Salary:<input type=text name=salary size=12><br><br><input type=submit value="Submit"><input type=reset value="Reset"></form></body></html>
![Page 5: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/5.jpg)
#!/usr/bin/perl#payroll.cgi - saves name and address information to make a mailing listuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);#assign variables$name = param('name');$stadr = param('stadr');$city = param('city');$state = param('state');$zip = param('zip');$jobtype = param('jobtype');$jobcode = param('jobcode');$payperhr = param('payperhr');$salary = param('salary');#save form data to a fileopen(FILEOUT, ">>", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";print FILEOUT "$name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary\n";close(FILEOUT);print "<html><head><title>Record just entered</title><basefont size=5></head>\n";print "<body>\n";print "<div align=center>\n";print "$name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary\n";print "</div></body></html>\n";
Code to write records to sequential file.
![Page 6: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/6.jpg)
#!/usr/bin/perl#payrollrd.cgi - reads the payroll fileuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);open(INF, "<", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";while(<INF>) { chomp($_); ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary) = split(/,/,$_); print "$name<br>\n"; }close(INF);print "</body></html>\n";
The while loop in this case is set up to handle all the records in the file. This is coded with while(<INF>) where INF is the name I used to open and close the file. The code in the while loop is enclosed with curly brackets.
![Page 7: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/7.jpg)
#!/usr/bin/perl#payrollsal.cgi - reads the payroll fileuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);open(INF, "<", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";print "<html><head><title>Salaried Workers</title><basefont size=5></head>\n";print "<body>\n";print "<h1>Salaried Workers:</h1>\n";while(<INF>) { chomp($_); ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary) = split(/, /,$_); if ($jobtype eq "S") { print "$name - Salaried - $jobtype<br>\n"; } }close(INF);print "</body></html>\n";
Note that the split divider is given as ,space.
![Page 8: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/8.jpg)
#!/usr/bin/perl#payrollsal1.cgi - reads the payroll fileuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);open(INF, "<", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";print "<html><head><title>Salaried Workers</title><basefont size=5></head>\n";print "<body>\n";print "<h1>Salaried Workers:</h1>\n";while(<INF>) { chomp($_); ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary) = split(/, /,$_); if ($jobtype eq "S") { print "$name - Salaried - $jobtype<br>\n"; } else { print "$name - Hourly - $jobtype<br>\n"; } }close(INF);print "</body></html>\n";
![Page 9: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/9.jpg)
#!/usr/bin/perl#payrolljobcd.cgi - reads the payroll fileuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);open(INF, "<", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";print "<html><head><title>Salaried Workers</title><basefont size=5></head>\n";print "<body>\n";print "<h1>Salaried Workers:</h1>\n";while(<INF>) { chomp($_); ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary) = split(/, /,$_); if ($jobcode == 1 ) { print "$name - Job Type #1 - $jobcode<br>\n"; } else { print "$name - All Other Job Types - $jobcode<br>\n"; } }close(INF);print "</body></html>\n";
![Page 10: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/10.jpg)
if ($jobcode == 1 ) { print "$name - Job Type #1 - $jobcode<br>\n"; } else { print "$name - All Other Job Types - $jobcode<br>\n"; }
![Page 11: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/11.jpg)
#!/usr/bin/perl#payrollsalamt.cgi - reads the payroll fileuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);open(INF, "<", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";print "<html><head><title>Employees</title><basefont size=5></head>\n";print "<body>\n";print "<h1>Employees:</h1>\n";while(<INF>) { chomp($_); ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary) = split(/, /,$_); if ($jobtype eq "S") { if ($salary >= 50000) { print "$name - $salary - Salary greater than 50000<br>\n"; } else { print "$name - $salary - Salary not greater than or equal to 50000<br>\n"; } } else { print "$name - $payperhr - Hourly employee<br>\n"; } }close(INF);print "</body></html>\n";
![Page 12: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/12.jpg)
jobtype eq “S”
salary >= 50000
Salary > 50000Salary not >
50000
Hourly employee
Y
Y
N
N
if ($jobtype eq "S") { if ($salary >= 50000) { print "$name - $salary - Salary greater than 50000<br>\n"; } else { print "$name - $salary - Salary not greater than or equal to 50000<br>\n"; } } else { print "$name - $payperhr - Hourly employee<br>\n"; }
![Page 13: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/13.jpg)
![Page 14: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/14.jpg)
#!/usr/bin/perl#payrollcom.cgi - reads the payroll fileuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);open(INF, "<", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";print "<html><head><title>Employees</title><basefont size=5></head>\n";print "<body>\n";print "<h1>Employees:</h1>\n";while(<INF>) { chomp($_); ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary) = split(/, /,$_); if ($jobtype eq "S" and $salary >= 50000) { print "$name - $salary - Salary greater than 50000<br>\n"; } else { print "$name - other employees<br>\n"; } }close(INF);print "</body></html>\n";
![Page 15: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/15.jpg)
if ($jobtype eq "S" and $salary >= 50000) { print "$name - $salary - Salary greater than 50000<br>\n"; } else { print "$name - other employees<br>\n"; }
jobtype eq “S”
salary >= 50000
Salary > 50000Other
employee
Otheremployee
Y
Y
N
N
![Page 16: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/16.jpg)
![Page 17: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/17.jpg)
#!/usr/bin/perl#payrollcomor.cgi - reads the payroll fileuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);open(INF, "<", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";print "<html><head><title>Employees</title><basefont size=5></head>\n";print "<body>\n";print "<h1>Employees:</h1>\n";while(<INF>) { chomp($_); ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary) = split(/, /,$_); if ($jobtype eq "S") { print "$name - $jobtype - $jobcode - jobtype = S<br>\n"; } else { if ($jobcode == 1) { print "$name - $jobtype - $jobcode - jobcode = 1<br>\n"; } else { print "$name - other employees<br>\n"; } } }close(INF);print "</body></html>\n";
![Page 18: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/18.jpg)
if ($jobtype eq "S") { print "$name - $jobtype - $jobcode - jobtype = S<br>\n"; } else { if ($jobcode == 1) { print "$name - $jobtype - $jobcode - jobcode = 1<br>\n"; } else { print "$name - other employees<br>\n"; } }
jobtype eq “S”
jobcode= 1
jobcode= 1Other
employee
Y
Y
N
N
jobtype=S
![Page 19: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/19.jpg)
![Page 20: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/20.jpg)
#!/usr/bin/perl#payrollcomor.cgi - reads the payroll fileuse CGI::Carp qw(fatalsToBrowser);print "Content-type: text/html\n\n";use CGI qw(:standard);use strict;#declare variablesmy ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary);open(INF, "<", "payroll.txt")
or die "file error: payroll.txt. $!, stopped";print "<html><head><title>Employees</title><basefont size=5></head>\n";print "<body>\n";print "<h1>Employees:</h1>\n";while(<INF>) { chomp($_); ($name, $stadr, $city, $state, $zip, $jobtype, $jobcode, $payperhr, $salary) = split(/, /,$_); if ($jobtype eq "S" or $jobcode == 1) { print "$name - $jobtype - $jobcode - either S or 1<br>\n"; } else { print "$name - other employees<br>\n"; } }close(INF);print "</body></html>\n";
![Page 21: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/21.jpg)
if ($jobtype eq "S" or $jobcode == 1) { print "$name - $jobtype - $jobcode - either S or 1<br>\n"; } else { print "$name - other employees<br>\n"; }
jobtype eq “S”
jobcode= 1
Either S or 1Other
employee
Y
Y
N
N
Either S or 1
![Page 22: IF statements - selection Please use speaker notes for additional information!](https://reader036.vdocuments.mx/reader036/viewer/2022062423/5697bfd91a28abf838caf750/html5/thumbnails/22.jpg)