G'day Wiggins,

As you've already seen, "_{$v1}_" was close, and just needed a small adjustment: "_${v1}_".

Another option is to use a formatted string with sprintf or printf. Here's an example:

$ perl -e 'my ($v1, $v2) = qw{A B}; printf "_%s_%s_\n", $v1, $v2' _A_B_

Here's a further option. It's a bit unwieldy; probably not what you'd want to reach for first; but this type of solution (using join) can occasionally be useful:

$ perl -le 'my ($v1, $v2) = qw{A B}; print join "_", "", $v1, $v2, ""' _A_B_

A more appropriate context for using that join solution might be something closer to this:

$ perl -le 'my @x = "A" .. "Z"; print join "_", "", @x, ""' _A_B_C_D_E_F_G_H_I_J_K_L_M_N_O_P_Q_R_S_T_U_V_W_X_Y_Z_

— Ken


In reply to Re: A simple question that can't be asked by kcott
in thread A simple question that can't be asked by Wiggins

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.