#!/usr/bin/perl # check command-line for validity die "syntax: $0 user passwd [-r | -a task priority]\n\t" if ! defined $ARGV[1]; # validate username/password pair $uname = shift; $passwd = shift; # open user data file open UDATA, ") { chomp $line; ($u, $p) = split /:/, $line; $ubase{$u} = $p; } close UDATA; # find command-line args in hash or exit die "cannot find user $uname\n\t" if ! defined $ubase{$uname}; die "cannot validate user password\n\t" if $passwd ne $ubase{$uname}; # check for runtime options (-r or -a) if (! defined $ARGV[0]) { $mode = "report"; } elsif ($ARGV[0] =~ /^-r/) { $mode = "report"; } elsif ($ARGV[0] =~ /-a/) { $mode = "add"; $dummy = shift; $newtask = shift; $priority = shift; } else { $mode = "report"; } # get existing task data open TDATA, ") { chomp $line; push @tlist, $line; } # here's a cheaper way # @tlist = ; close TDATA; # write report if we're in that mode if ($mode eq "report") { foreach $t (@tlist) { print "$t\n" if $t =~ $uname; } } # print out new data file if we're in that mode if ($mode eq "add") { $newitem = join ":", ($uname, $newtask, $priority); push @tlist, $newitem; foreach $line (@tlist) { print "$line\n"; } } #### larry:lingo tom:tonic ellie:plasma #### larry:finish autostory program:3 larry:read about file i/o:2 tom:order 12 gallons of Vitalis:1 ellie:find planet-related websites:2 tom:get more paper for clipboard:3 randal:write roster management program:2 #### cannot validate user password at todo001.pl line 23.