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