cgmd has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unable to run or troubleshoot a script...
by GrandFather (Saint) on Jun 26, 2007 at 02:37 UTC | |
by cgmd (Beadle) on Jun 26, 2007 at 03:37 UTC | |
by GrandFather (Saint) on Jun 26, 2007 at 03:46 UTC | |
by cgmd (Beadle) on Jun 26, 2007 at 11:46 UTC | |
by clinton (Priest) on Jun 26, 2007 at 13:16 UTC | |
by graff (Chancellor) on Jun 26, 2007 at 18:50 UTC | |
|
Re: Unable to run or troubleshoot a script...
by naikonta (Curate) on Jun 26, 2007 at 02:37 UTC | |
by cgmd (Beadle) on Jun 26, 2007 at 03:14 UTC | |
|
Re: Unable to run or troubleshoot a script...
by chrism01 (Friar) on Jun 26, 2007 at 06:52 UTC | |
by cgmd (Beadle) on Jun 26, 2007 at 12:22 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |