in reply to Bad file slurp or Bad Dumper code?
Yes, you do need to move the close out of the while loop. However I have a couple of questions:
1) Why are you assigning to @_ ? @_ is a special Perl var, and it is confusing (to me at any rate) to see you using it as a simple scratch array.
2)Why aren't you returning the hash? If a subroutine has no return value, I find that the main code is confusing because there is the magic hash (or other var) that appears and I don't know to associate it with the routine that created it.
Additionally the use of globals (%passfile and $pass_file) is generally bad practice, and should be avoided.
Here's how I would write it (just a suggestion mind you)
Cheers,sub read_passfile { my $file_name = shift; #Pass the file name to the routine my @temp; my %passfile = (); open (PF, $file_name) or die "Couldn't read password file: $!"; while (<PF>) { chomp; @temp = split("\t", $_); $passfile{ $temp[0] } = $temp[1]; } close PF; return %passfile; }
Update:Fixed a silly typo. Thanks jeffa
|
|---|