in reply to Re: Re: Using my and library....
in thread Using my and library....
More tweaking produces:# hash.lib # in the library sub gethash { my %hash; open(FILE, "data.txt") || die "Can't open data - $!\n"; # dick:98 # robert:76 # mary:68 chomp(my @lines = <FILE>); close(FILE); foreach (@lines) { my ($name,$score) = split /:/, $_; $hash{name} = $name; $hash{score} = $score; } return \%hash; }
# hash.lib # in the library sub gethash { open(FILE, "data.txt") || die "Can't open data - $!\n"; my %hash = map { (split(/:/))[0,1] } chomp(<FILE>); close(FILE); return \%hash; }
|
|---|