in reply to Re^2: Convert a string into a hash
in thread Convert a string into a hash
my %code = do { my $i = 0; map { $_ => $i++ } split /,/, $tokens };
If you really want no explicitely declared temp variables, you can use the following:
my %code = sub { map { $_[$_] => $_ } 0..$#_ }->( split /,/, $tokens ) +;
But honestly, there's no need to limit the scope that badly. Either of the following are quite suitable:
my $i = 0; my %code = map { $_ => $i++ } split /,/, $tokens;
my @code = split /,/, $tokens; my %code = map { $code[$_] => $_ } 0..$#code;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Convert a string into a hash
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 |