I'm writing a function that expects either a 4 digit number or a 4digit number followed by an underscore and 3 more digits. (ie: 9999 or 9999_002) If the value only contains 4 digits I want to append "_001" to the end. I could have sworn that all I needed to do was: (pseudo code follows)

my ($new_retid) = $retid =~ /_\d{3}$/ || "${retid}_001";

This of course does not work. $new_retid is always a 1.
It always bugs me that I can't remeber stuff like this. And trying to find answers like this quickly is a challenge(but I do try).
As always,

Thank you!


In reply to Variable assignment confusion by sweetblood

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.