Name Age Regn No.
A 50 r1
B 40 r2
C 30 r3
####
#!/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;
####
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\x>cd desktop
C:\Users\x\Desktop>d2.pl
Press 1 to insert new data:
Press 2 to view data:
Press 3 to call specific data: 1
Enter Student's Name: A
Enter Age (yr): 50
Enter Regn Number: r1
Press 1 to insert new data:
Press 2 to view data:
Press 3 to call specific data: 1
Enter Student's Name: B
Enter Age (yr): 40
Enter Regn Number: r2
Press 1 to insert new data:
Press 2 to view data:
Press 3 to call specific data: 1
Enter Student's Name: C
Enter Age (yr): 30
Enter Regn Number: r3
Press 1 to insert new data:
Press 2 to view data:
Press 3 to call specific data: 2
Here goes the Final Database:
A:50:r1
B:40:r2
C:30:r3
Press 1 to insert new data:
Press 2 to view data:
Press 3 to call specific data: 3
Use of uninitialized value $reg_no in hash element at C:\Users\x\Desktop\d2.pl line 52, line 17.
Enter the Regn Number for detailed information: