Oh Fonts of Knowledge,

I am trying to populate a variable($tkt_data) to create a string that is structured as below:

"2", "submitted by", "7", "Status", "8", "a short, concise description +", "536870915", "Jobfail", "536870922", "finance", "536870926", "Stev +ens"
The data pair should only be included in the string if the variable contains a value and a comma should be appended at the end of each pair only if another pair is to be appended.

The data and variables are layed out as follows:

..........................# VALUE CONTAINED IN THE VARIABLE "2", "$p_suby", # submitted by "7", "$p_stat", # Status "8", "$p_desc", # a short concise description "536870915", "$p_catg", # Jobfail "536870922", "$p_agrp", # finance "536870926", "$p_lnam" # Stevens
Things I've tried that failed:
$counter = 0 ; if ($p_suby != "") {$tkt_data = "\"2\", \"$p_suby\"" ; $counter = $counter + 1 ;} if ($p_stat != "") {if ($counter > 0) {$tkt_data = "$tkt_data, \"7\", \"$p_stat\""} else {$tkt_data = "\"7\", \"$p_stat\""} $counter = $counter + 1 ;} if ($p_desc != "") {if ($counter > 0) {$tkt_data = "$tkt_data, \"8\", \"$p_desc\""} else {$tkt_data = "\"8\", \"$p_desc\""} $counter = $counter + 1 ;} if ($p_catg != "") {if ($counter > 0) {$tkt_data = "$tkt_data, \"536870915\", \"$p_catg +\""} else {$tkt_data = "\"536870915\", \"$p_catg\""} $counter = $counter + 1 ;} if ($p_agrp != "") {if ($counter > 0) {$tkt_data = "$tkt_data, \"536870922\", \"$p_agrp +\""} else {$tkt_data = "\"536870922\", \"$p_agrp\""} $counter = $counter + 1 ;} if ($p_lnam != "") {if ($counter > 0) {$tkt_data = "$tkt_data, \"536870926\", \"$p_lnam +\""} else {$tkt_data = "\"536870926\", \"$p_lnam\""} $counter = $counter + 1 ;}

In reply to 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.