Let me presume to answer for tybalt89.
my ($cluster, $member) = split;
This depends on default behavior of split, and is equivalent to
my ($cluster, $member) = split ' ', $_;
The ' ' split pattern is a special case explained in split docs.
print $cluster eq $member ? "\n" x ($. > 1) : ', ', $member;
This is a bit more tricksy. From the inside out:
-
($. > 1) $. is input line counter (update: see perlvar). ($. > 1) evaluates to either '' (empty string) or 1 and will be 1 for every input line after the first.
-
"\n" x ($. > 1) Repeats a newline zero times for the first line of input (empty string silently promoted to 0 in this special case), once for every subsequent input line.
-
$cluster eq $member ? Newline_or_Nada : ', ' Ternary expression. If $cluster eq $member true, output newline for every input line after the first (see previous item); if false, output ', ' string.
-
print Ternary_Expression, $member; print result of ternary expresssion (see previous item), then $member string.
And that's all there is to it (I think).
Update: Minor wording changes.
Give a man a fish: <%-{-{-{-<
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.