in reply to Problem generating a hashtable
One suggestion though, would be to change the map so that the split() is only done once (no functionality change, just for efficiency):use strict; use warnings; my %hash = map { (split /:/, $_ )[0] => (split /:/, $_ )[2] } <DATA>; print join ( "\n", sort keys %hash ) . "\n"; __DATA__ k1:asd:v1 k2:asd:v2
(could also do map { (split(/:/, $_)) [0,2] } but that's not as clear that it's key/value pairs)map { my @tmp = split /:/, $_; $tmp[0] => $tmp[2]; } <FILE>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem generating a hashtable
by techra (Pilgrim) on May 13, 2005 at 14:36 UTC | |
|
Re^2: Problem generating a hashtable
by Tomtom (Scribe) on May 13, 2005 at 13:34 UTC | |
|
Re^2: Problem generating a hashtable
by blazar (Canon) on Jul 19, 2005 at 14:23 UTC |