Win8 Strawberry 5.8.9.5 (32) Tue 03/16/2021 21:10:53 C:\@Work\Perl\monks >perl -Mstrict -Mwarnings my $abc = 'dgrs'; $_ = 1; # print $temp_out "$abc . _$_;\n"; # not this, with extra dot and spa +ces print 'A: ', $abc . "_$_", "\n"; # but this ... print 'B: ', "${abc}_$_", "\n"; # or this. print "C: ${abc}_$_;\n"; # update: or even this. ^Z A: dgrs_1 B: dgrs_1 C: dgrs_1;

Update 1: In example B or C above, what happens if the {} curly braces are left out of the "${abc}_$_" expression, so it becomes "$abc_$_"? Try it! Do you get the desired or expected result? If not, why not?

Update 2: Examples of 1nickt's approach++ and one other. Note that the concern about curly braces goes away.

Win8 Strawberry 5.8.9.5 (32) Tue 03/16/2021 23:02:15 C:\@Work\Perl\monks >perl -Mstrict -Mwarnings my $abc = 'dgrs'; $_ = 1; printf "D: %s_%d;\n", $abc, $_; my $spf = sprintf "E: %s_%d;\n", $abc, $_; print $spf; my $fmt_dgrs = "F: %s_%d;\n"; printf $fmt_dgrs, $abc, $_; print join '', 'G: ', $abc, '_', $_, ';', "\n" ^Z D: dgrs_1; E: dgrs_1; F: dgrs_1; G: dgrs_1;


Give a man a fish:  <%-{-{-{-<


In reply to Re: How to combine string and digits in perl (updated x2) by AnomalousMonk
in thread How to combine string and digits in perl by suvendra123

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.