#!/usr/bin/perl use warnings; ################################################ my %studentsDB; my $key=shift || 0; ############################################## ## Output to a TEXT File using file handle: ############################################## $output="Rdata.txt"; open (my $fh,">",$output) or die"Cannot open file '$output'.\n"; ############################ # Constants: $colon=":"; $dash="~~~"; ############################ do { print"\n\n Press 1 to insert new data: "; print"\n Press 2 to view data: "; print"\n Press 3 to call specific data: "; $entry=; chomp $entry; if ($entry==1) { print"\n\n Enter Student's Name: "; $nme1=; chomp $nme1; $nme=$nme1.$colon; push @nme, $nme; print"\n Enter Age (yr): "; $age1=; chomp $age1; $age=$age1.$colon; push @age, $age; print"\n Enter Regn Number: "; $rgn1=; chomp $rgn1; $rgn=$rgn1.$dash; push @rgn, $rgn; print"\n"; $ind=$nme.$age.$rgn; push @ind, $ind; $ind2=join ('',@ind);} elsif ($entry==2) { $ind=$nme.$age.$rgn; push @ind, $ind; $ind2=join ('',@ind); pop(@ind); $data=join ('',@ind); ################################# ## Now split DATA: ### ################################# my @values = split('~~~', $data); my $val=''; print"\n\n\n Here goes the Final Database:\n"; foreach $val (@values) { print $fh "$val"; print $fh "\n"; print"\n"; print"$val"; } close $output;} elsif ($entry==3) { while () { my ($name, $age, $reg_no )=split":"; $studentsDB {$reg_no}={Name => $name, # Line 52: uninitialized reg_no Age => $age,};} print"\n Enter the Regn Number for detailed information:\n"; $key=; chomp $key; if ($key) { # Print the details of the preselected student: print "Information for student with registration number $key is: \n"; print " Name: " . $studentsDB{$key}{Name} . "\n"; print " Age: " . $studentsDB{$key}{Age} . "\n"; } else { # Print the name for each student we have a record for: print "\n List of All Students:\n"; foreach my $id (sort keys %studentsDB) { print " Registration Number: " . $id . "\n"; print " Name: " . $studentsDB{$id}{Name} . "\n"; print " Age: " . $studentsDB{$id}{Age} . "\n"; } } } } until ($entry==3); exit;