in reply to hash and array mismatch
You are using the same key for multiple values. You will only retain the last value assigned to the hash for a given key. For example 'TOTAL QUALITY' has values 8 and 14, only 14 is retained.
Most likely a hash is not appropriate for whatever you are trying to achieve. You could however:
use warnings; use strict; use Data::Dump::Streamer; my @data = <DATA>; my %dataPos; chomp @data; push @{$dataPos{$data[$_]}}, $_ for 0 .. $#data; Dump (\%dataPos); __DATA__ WELL TOTAL QUALITY POSITION NAME TOTAL QUALITY POSITION NAME
Prints:
$HASH1 = { "" => [ 3 ], "POSITION NAME" => [ 2, 5 ], "TOTAL QUALITY" => [ 1, 4 ], WELL => [ 0 ] };
Which creates a list of positions for each key value.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash and array mismatch
by TGI (Parson) on May 10, 2007 at 17:06 UTC | |
by GrandFather (Saint) on May 10, 2007 at 19:19 UTC | |
by TGI (Parson) on May 10, 2007 at 20:19 UTC |