Just accumulate, then print.
foreach $field (param) { # Isolate non-empty values my @values = grep { ! /^\s*$/ } param($field); next unless @values; # Skip if nothing available # Establish a header line. Note that I added an "Other" class my $header = "Other:"; $header = "First:" if $field =~ /Data_One/; $header = "Second:" if $field eq /Second_Part/; # Print it all. $, is the output record separator for prints local $, = "\n"; print $header, @values, "\n"; }
Untested, but you get the idea. Note that localising $, inside the foreach isn't a very smart idea for performance issues, you'd better localising it slightly outside the loop if you want to gain some CPU cycles.

Moreover, if you're only interested into these two selection boxes, you'd better iterate over them directly:

foreach $field (qw(Data_One Second_Part)) { # Isolate non-empty values my @values = grep { ! /^\s*$/ } param($field); next unless @values; # Skip if nothing available # Establish a header line. my $header = "First:"; $header = "Second:" if $field =~ /Second_Part/; # Print it all. $, is the output record separator for prints local $, = "\n"; print $header, @values, "\n"; }

Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

Don't fool yourself.

In reply to Re: Distinct field name output attempt by polettix
in thread Distinct field name output attempt 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.