in reply to Convert a string into a hash
I suspect all you want is-
my @code = split /,/, $tokens;If you're keeping hash with indices as values, it makes more sense to use an array. There's also this if you really don't care about the indices-
my %code = map { $_ => 1 } split /,/, $tokens;Update: there's also this but I think your original version is easier for most to read-
my %code; my @code = split /,/, $tokens; $code{$code[$_]} = $_ for 0 .. $#code;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Convert a string into a hash
by vitoco (Hermit) on Aug 14, 2009 at 22:41 UTC | |
by ikegami (Patriarch) on Aug 15, 2009 at 02:18 UTC | |
by vitoco (Hermit) on Aug 15, 2009 at 03:34 UTC | |
by ikegami (Patriarch) on Aug 15, 2009 at 15:48 UTC | |
by vitoco (Hermit) on Aug 15, 2009 at 16:56 UTC | |
by Your Mother (Archbishop) on Aug 14, 2009 at 23:20 UTC | |
by ikegami (Patriarch) on Aug 15, 2009 at 02:25 UTC | |
by Your Mother (Archbishop) on Aug 15, 2009 at 04:27 UTC | |
by ikegami (Patriarch) on Aug 15, 2009 at 15:52 UTC | |
by vitoco (Hermit) on Aug 15, 2009 at 03:19 UTC | |
by roboticus (Chancellor) on Aug 15, 2009 at 13:04 UTC |