Ok this should work, Im teaching my self Perl and I can get chunks of code to work, BUT when I put it together it craps out on me. Can somebody tell me what is worng with this?
The problem is in the sub showOneRecord
When I rund that chunk of code by its self it works just right, but the second I add that code to the sub then it takes a crap on me. What am I missing?
CODE FOLLOWS
print "\nThis program writes to a flie,\n";
print "\nPress any key to continue...";
$anychar=<stdin>;
for(;{
print"\n\t1. Add Record";
print"\n\t5. View All Records.";
print "\n\tWhat action do you want to perform?\n\t";
$answer = <STDIN>;
chomp($answer);
if($answer =~ /^1/i){
#add
print "\n\tOption 1.\n";
enterData();
last;
}
elsif($answer =~ /^5/i){
#view all
print "\n\tOption 5.\n";
showAll();
last;
}
else{
print "\n\tMust select a valid option.\n";
next;
}
}#end for
sub enterData {
#---------------Inputs user data into Vars
print "\nBuilding you into the data base...\n ";
print "\nEnter Your Name: ";
$namedata = <stdin>;
chomp($namedata);
print "\nEneter your Email address: ";
$emaildata =<stdin>;
chomp($emaildata);
print "\nEnter your Street Address: ";
$streetadd = <stdin>;
chomp($streetadd);
print "\nEnter your city: ";
$city = <stdin>;
chomp ($city);
print "\nEnter your State: ";
$state= <stdin>;
chomp($state);
print "\nEnter your zip code: ";
$zip = <stdin>;
chomp($zip);
}
#---------------------list all records
sub showOneRecord{
print "\n\nNow printing a list of all records";
print "\n\tPress any key to print";
$anychar=<stdin>;
open(RFH,"<basicdata.txt"||die("File could not be opend: $!"
$count=0;
while(my $line= <RFH>)
{
print "$line\n";
$count++;
if($count%15==0)
{
print "Push any key to continue ";
$count=0;
}
}
close(RFH);
$anychar=<stdin>;
}
The problem is in the sub showOneRecord
When I rund that chunk of code by its self it works just right, but the second I add that code to the sub then it takes a crap on me. What am I missing?
CODE FOLLOWS
print "\nThis program writes to a flie,\n";
print "\nPress any key to continue...";
$anychar=<stdin>;
for(;{
print"\n\t1. Add Record";
print"\n\t5. View All Records.";
print "\n\tWhat action do you want to perform?\n\t";
$answer = <STDIN>;
chomp($answer);
if($answer =~ /^1/i){
#add
print "\n\tOption 1.\n";
enterData();
last;
}
elsif($answer =~ /^5/i){
#view all
print "\n\tOption 5.\n";
showAll();
last;
}
else{
print "\n\tMust select a valid option.\n";
next;
}
}#end for
sub enterData {
#---------------Inputs user data into Vars
print "\nBuilding you into the data base...\n ";
print "\nEnter Your Name: ";
$namedata = <stdin>;
chomp($namedata);
print "\nEneter your Email address: ";
$emaildata =<stdin>;
chomp($emaildata);
print "\nEnter your Street Address: ";
$streetadd = <stdin>;
chomp($streetadd);
print "\nEnter your city: ";
$city = <stdin>;
chomp ($city);
print "\nEnter your State: ";
$state= <stdin>;
chomp($state);
print "\nEnter your zip code: ";
$zip = <stdin>;
chomp($zip);
}
#---------------------list all records
sub showOneRecord{
print "\n\nNow printing a list of all records";
print "\n\tPress any key to print";
$anychar=<stdin>;
open(RFH,"<basicdata.txt"||die("File could not be opend: $!"
$count=0;
while(my $line= <RFH>)
{
print "$line\n";
$count++;
if($count%15==0)
{
print "Push any key to continue ";
$count=0;
}
}
close(RFH);
$anychar=<stdin>;
}