student.pl ---------- #!/usr/bin/perl use strict; use warnings; open(FILE, "marks.txt") || die("cannot access the file"); my($fullname,$markseachsubject,$totalmarks,$percentage,@marks,@total,$marks,$status,@rank,$mark,$value,%records); while(my $line=){ next if $line=~/^NAME/; chomp($line); $line=~/(\w+),(\w+),(\d+),(\d+),(\d+)/; $fullname=$1." ".$2; push(@marks,$3,$4,$5); foreach $mark(@marks){ $status=checkpass($mark); } $markseachsubject=$3." ".$4." ".$5." ".$status; $totalmarks=$3+$4+$5; @total=$totalmarks; $percentage=$totalmarks/3; $percentage=sprintf("%.2f",$percentage); if($status eq "Pass"){ print $fullname." "."\t".$markseachsubject." "."\t".$totalmarks." "."\t".$percentage; print "\n"; }else{ print $fullname." "."\t".$markseachsubject." "."\t"; print "\n"; } } #To check whether the student is pass or fail sub checkpass{ $marks=shift; if ($marks > 35){ $status="Pass"; return $status; }else{ $status="Fail"; return $status; } } close FILE;