#!/usr/bin/perl use strict; do { cls(); print "Address Book\n"; $_ = <>; if (/l/) { entry_list(); } elsif (/a/) { entry_add(); } elsif (/r/) { entry_rem(); } elsif (/s/) { entry_sea(); } else { print "Invalid Entry\n" if not /[lars(q|quit)]/; } } until(/q|quit/); exit; sub entry_list { cls(); open ADBK, "<adbk.db" || die "Datebase file does not exist\n"; while(<ADBK>) { print join(" ", split /:/); } close ADBK; print "Press any key to contine...\n"; $_ = <>; } sub entry_rem { my $tmp = (); my $num = 0; print "Enter the infomation:\n"; foreach("First Name: ", "Last Name: ", "Email: ") { print; chomp(my $line = <>); $tmp .= "$line:"; } cls(); open ADBK, "<adbk.db" || die "Could not open database to read\n"; my @file = <ADBK>; close ADBK; open ADBK, ">adbk.db" || die "Could not open database to open\n"; foreach ( @file) { next if /$tmp/; $num++; print ADBK $_; } close ABDK; print "No entries found\n" if $num == 0; print "Press any key to contine...\n"; $_ = <>; } sub entry_sea { my $tmp = (); my $num = 0; print "Enter the infomation:\n"; foreach("First Name: ", "Last Name: ", "Email: ") { print; chomp(my $line = <>); $tmp .= "$line:"; } cls(); open ADBK, "<adbk.db" || die "Could not open database to read\n"; while(<ADBK>) { if(/$tmp/) { print "Entry ", ++$num, ":\n", join("\n", split /:/) +; } } close ABDK; print "No entries found\n" if $num == 0; print "Press any key to contine...\n"; $_ = <>; } sub entry_add { my $tmp = (); foreach("First Name: ", "Last Name: ", "Email: ") { print; chomp(my $input = <>); $tmp .= $input.":"; } open ADBK, ">>adbk.db" || die "Could not open database to append\n"; print ADBK $tmp, "\n"; close ABDK; } sub cls { print "\033[2J"; print "\033[0;0f"; }
In reply to Re: Learning Exercise
by debiandude
in thread Learning Exercise
by Foncé
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |