Try thinking in steps.
  1. You have a list of stuff.
  2. You want to get a sub-list of specific stuff.
  3. You want to perform some action on that sub-list.
############################## # 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.