in reply to Re: Convert a string into a hash
in thread Convert a string into a hash
Ok, I am going to go "crazy" here and ask why you want a hash in the first place?
I just want to iterate the elements of another list of tokens, but in the same order them appear in the main list of tokens. Simplified:
my $tokens = "32,15,4,72,13,28,14"; my %code = do { my $i = 0; map { $_ => $i++ } split /,/, $tokens }; my $list = "4,13,15"; my $ok; for my $token (sort { $code{$a} <=> $code{$b} } split /,/, $list) { print "$token "; # more code with $token... last if $ok; } __END__ 15 4 13
Obviously, both $tokens and $list are dynamically loaded from somewhere else...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Convert a string into a hash
by Marshall (Canon) on Aug 15, 2009 at 07:05 UTC | |
by vitoco (Hermit) on Aug 15, 2009 at 16:29 UTC | |
by Marshall (Canon) on Aug 18, 2009 at 17:47 UTC | |
by vitoco (Hermit) on Aug 18, 2009 at 21:22 UTC | |
by Marshall (Canon) on Aug 19, 2009 at 00:49 UTC | |
|
Re^3: Convert a string into a hash
by Marshall (Canon) on Aug 15, 2009 at 07:18 UTC |