########################################## # FINDING DETAILS OF A STUDENT: ##### ########################################## #!/usr/bin/perl use warnings; use strict; ######################## # DATABASE Input: ### ######################## print "\n\n Please ENTER Database Name (.txt): "; my $DNAfilename=; chomp $DNAfilename; # open the file, or exit: unless (open(DNAFILE, $DNAfilename) ) { print "Cannot open file \"$DNAfilename\"\n\n"; exit;} my @DNA= ; print"\n $DNAfilename Database:\n\n"; print @DNA; print"\n"; ########################## ## CODE STARTS HERE: ########################## {package Student; sub new {my ($name, $age, $regd_no)=@_; my $self={ NAME => $name, AGE => $age, REGD_NO => $regd_no}; return bless $self, my $class;print"\n class: $class\n"; } sub display { my ($self) = @_; if ($self) { print 'Student Name: ', $self->{NAME}, "\n"; print 'Age (yr): ', $self->{AGE}, "\n"; print 'Regd no: ', $self->{REGD_NO}, "\n"; } } } my @students; while () {chomp; push @students, Student->new(split /:/);} print"\n WELCOME to Students' Database:\n"; print"\n Enter the Registration Number to view the details: "; my $reg=; chomp $reg; find_student($reg)->display(); # LINE 45 sub find_student {my ($regd_no) = @_; print"\n\n"; print"\n The details of the student are:\n\n"; for (@students) {return $_ if $_->{REGD_NO} eq $regd_no;} return undef;} print"\n\n";