1: #!/usr/bin/perl -w
2: #####################################################################
3: # This is a test program to start work on building up some real #
4: # skill with Perl. Also, must remember to refer to Perl as Perl and #
5: # not PERL. Someone might get offended. #
6: # The purpose of this program is to create and read a small #
7: # flat-file database of birthdays to remember. Boring but useful. #
8: # Please be kind to me, this is my first Perl application and I #
9: # was hoping to get some feedback. Maybe the community can tell me #
10: # If I'm starting out good? So many of these ideas are still new to #
11: # me because I'm so used to PHP's style. #
12: #####################################################################
13:
14: use strict; # Enforce legal variables.
15:
16: my ($choice); # The user's choice.
17: my ($name); # Person's name
18: my ($date); # Birthday
19: my (@birthdays); # List of Birthdays.
20: my ($key);
21:
22: while () {
23: print "(L)ist or (N)ew or (M)odify birthday? "; chomp($choice = <STDIN>);
24: if ($choice =~ /l/i) {
25: # User picked List
26: open (IN, "birthdays.db") || die "Failure: $!";
27: while (<IN>) {
28: print;
29: } # Print it all to the screen
30: close (IN);
31: } elsif ($choice =~ /n/i) {
32: open (OUT, ">>birthdays.db") || die"Failure: $!";
33:
34: print "Enter person's name: "; chomp ($name=<STDIN>);
35: print "Enter person's birthday: "; chomp ($date = <STDIN>);
36: print OUT "$name:$date\n";
37:
38: close (OUT);
39: } elsif ($choice =~ /m/i) {
40: open (IN, "birthdays.db");
41: push @birthdays, $_ while (<IN>);
42: close (IN);
43: $key = 0;
44: foreach (@birthdays) {
45: print "$key: $birthdays[$key]";
46: $key++;
47: } # Store file information in memory.
48: $key = "";
49: print "Enter record to modify: "; chomp ($key = <STDIN>);
50: print "(M)odify or (D)elete? "; chomp ($choice = <STDIN>);
51: open (OUT, ">birthdays.db");
52: $birthdays[$key] = "" if ($choice =~ /d/i);
53: print OUT @birthdays;
54: if ($choice =~ /m/i) {
55: print "Enter person's name: "; chomp ($name=<STDIN>);
56: print "Enter person's birthday: "; chomp ($date = <STDIN>);
57: $birthdays[$key] = "$name:$date\n";
58: print OUT @birthdays;
59: } # put it all back in the file.
60: close (OUT);
61: @birthdays = (); # Clear that annoying array. It causes problems if we don't.
62: }
63: }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Birthday List
by dragonchild (Archbishop) on Aug 28, 2003 at 13:41 UTC | |
by Drgan (Beadle) on Aug 29, 2003 at 00:06 UTC | |
by dragonchild (Archbishop) on Sep 01, 2003 at 19:19 UTC | |
|
Re: Birthday List
by TomDLux (Vicar) on Aug 28, 2003 at 18:05 UTC |