If I trim the cruft, use DATA (because this is a sample and I don't want to use external files), provide the user and password as constants (because this is a sample and I don't want to use STDIN), then:

#!/usr/bin/perl # read user data into a hash while ($line = <DATA>) { chomp $line; ($u, $p) = split /:/, $line; $ubase{$u} = $p; } my $uname = 'larry'; my $passwd = 'lingo'; # 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}; print "Validated user name and password\n"; __DATA__ larry:lingo tom:tonic ellie:plasma

Prints:

Validated user anme and password

as expected. Perhaps you didn't provide a correct password?

More important is to be aware of a couple of bad things this example is teaching you. First, always use strictures (use strict; use warnings;). The textbook example doesn't. Second, use the three parameter open because it's safer and clearer. Often too it's helpful to give the user the system generated error for a failed operation - die "couldn't open task data file: $!\n\t" (note the $!).


DWIM is Perl's answer to Gödel

In reply to Re: Unable to run or troubleshoot a script... by GrandFather
in thread 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.