Dear Monks...

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:

#!/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.users file:
larry:lingo tom:tonic ellie:plasma
The supporting todo.tasks file:
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
I'm curious why this fails with:
cannot validate user password at todo001.pl line 23.
Would someone please explain?

Thanks!


In reply to Unable to run or troubleshoot a script... by cgmd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.