kanka has asked for the wisdom of the Perl Monks concerning the following question:
and I wanna write and save it as Hash using that formula, here`s sample output:(Hash)Thomas 60 10 20 85 Samuel 35 90 80 65 Adam 100 90 85 52
I tried to do it like thisAdam 79.35 Samuel 69 Thomas 45
use strict; use Fcntl ':flock'; my $file = "inputdata.txt"; open(INFILE, $file) or die "File Not Found: $!"; flock(INFILE, LOCK_EX); my @students; while (<INFILE>) { push @students, [split / /, $_]; my %hash; my @keys = keys(%hash); @keys = sort(@keys); foreach my $key(@keys){ print $hash{$key} = $students[0]*0.2 + $students[1]*0.25 + $students[2 +]*0.25 + $students[3]*0.3, "\n"; } } close(INFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Create Hash from array structure
by tinita (Parson) on Mar 16, 2004 at 23:13 UTC | |
|
Re: Create Hash from array structure
by BrowserUk (Patriarch) on Mar 17, 2004 at 00:49 UTC | |
|
Re: Create Hash from array structure
by calin (Deacon) on Mar 17, 2004 at 11:26 UTC | |
|
Re: Create Hash from array structure
by kanka (Initiate) on Mar 17, 2004 at 14:04 UTC |