a comma should be appended at the end of each pair only if another pair is to be appended.
Sounds like a job for join. Build an array/list of all your "12345", "$p_xxxx" strings and join them with ", ".

As for the other restrictions, notice that you've had to hardcode every variable separately because they all have different ID numbers. If you were to group all the related $p_xxxx variables into one hash, and build a hash that maps record fields to ID numbers, your life could be a lot simpler:

my %id_map; my @fields = qw/suby stat desc catg agrp lnam/; @id_map{@fields} = qw/2 7 8 536870915 536870922 536870926/; ######### my %p_record = ( suby => "foo", stat => "bar", desc => "baz", catg => "", agrp => "boo", lnam => "" ); my $tkt_data = join ", " => map { qq["$id_map{$_}", "$p_record{$_}"] } grep { length $p_record{$_} } @fields; print "$tkt_data\n"; # "2", "foo", "7", "bar", "8", "baz", "536870922" +, "boo"
Now there are no individual cases, no plethora of if-statements, because all fields can now be handled the same way. Their ID number is fetched from the %id_map hash.

blokhead


In reply to Re: My Novice is Showing by blokhead
in thread My Novice is Showing by Red_Dragon

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.