#!/usr/bin/perl -w ##################################################################### # This is a test program to start work on building up some real # # skill with Perl. Also, must remember to refer to Perl as Perl and # # not PERL. Someone might get offended. # # The purpose of this program is to create and read a small # # flat-file database of birthdays to remember. Boring but useful. # # Please be kind to me, this is my first Perl application and I # # was hoping to get some feedback. Maybe the community can tell me # # If I'm starting out good? So many of these ideas are still new to # # me because I'm so used to PHP's style. # ##################################################################### use strict; # Enforce legal variables. my ($choice); # The user's choice. my ($name); # Person's name my ($date); # Birthday my (@birthdays); # List of Birthdays. my ($key); while () { print "(L)ist or (N)ew or (M)odify birthday? "; chomp($choice = ); if ($choice =~ /l/i) { # User picked List open (IN, "birthdays.db") || die "Failure: $!"; while () { print; } # Print it all to the screen close (IN); } elsif ($choice =~ /n/i) { open (OUT, ">>birthdays.db") || die"Failure: $!"; print "Enter person's name: "; chomp ($name=); print "Enter person's birthday: "; chomp ($date = ); print OUT "$name:$date\n"; close (OUT); } elsif ($choice =~ /m/i) { open (IN, "birthdays.db"); push @birthdays, $_ while (); close (IN); $key = 0; foreach (@birthdays) { print "$key: $birthdays[$key]"; $key++; } # Store file information in memory. $key = ""; print "Enter record to modify: "; chomp ($key = ); print "(M)odify or (D)elete? "; chomp ($choice = ); open (OUT, ">birthdays.db"); $birthdays[$key] = "" if ($choice =~ /d/i); print OUT @birthdays; if ($choice =~ /m/i) { print "Enter person's name: "; chomp ($name=); print "Enter person's birthday: "; chomp ($date = ); $birthdays[$key] = "$name:$date\n"; print OUT @birthdays; } # put it all back in the file. close (OUT); @birthdays = (); # Clear that annoying array. It causes problems if we don't. } }