############################## # This code has been tested. # ############################## # Step 1 - Get your starting list my @main_list= ('Currency','USD','Asset','Equity','Country','USA'); # Step 2 - Generate the sub-list my @sublist_indices = grep { !(($_ + 1) % 2) } (0 .. $#main_list); my @sublist = @main_list[@sublist_indices]; # Step 3 - Do the action(s) on the sub-list my $string = join '_', @sublist; print "'$string'\n";
Because you're dealing with every other element, some people will suggest using a hash. But, a hash has two problems:
The solution I (and others) have above will work for any rule for determining the sublist indices.
------
We are the carpenters and bricklayers of the Information Age.
The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
In reply to Re: selective join
by dragonchild
in thread selective join
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |