in reply to Unable to run or troubleshoot a script...
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 $!).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unable to run or troubleshoot a script...
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 |