I've come across a script (in a Perl textbook) that fails to run properly, and I'm requesting some help troubleshooting it. The actual script:
The supporting todo.users file:#!/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, "<todo.users" || die "couldn't open user data file."; # read user data into a hash while ($line = <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, "<todo.tasks" || die "couldn't open task data file\n\t"; while ($line = <TDATA>) { chomp $line; push @tlist, $line; } # here's a cheaper way # @tlist = <TDATA>; 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"; } }
The supporting todo.tasks file:larry:lingo tom:tonic ellie:plasma
I'm curious why this fails with: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
Would someone please explain?cannot validate user password at todo001.pl line 23.
Thanks!
In reply to Unable to run or troubleshoot a script... by cgmd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |