I'm looking for an easy way to overwrite the empty string in a variable.

For undefined variables, I use the following:

$var //= '?';

Which means (to me at least), "If $var is undef, then assign it the value '?'".

I would like something similar for the case when $var contains '', e.g.

$var ///= '';

where I fabricated the '///=' operator for the purposes of illustration.

Currently, I use the following syntax:

$var = '?' if $var eq '';

Can anyone think of a tighter syntax? The above approach becomes cumbersome as variable names increase in length. (Hmm, as I write this, I'm considering that perhaps long variable names are the root cause of this issue. I do a lot of coding around SNMP, and so end up with extravaganzas like $dot3adAggPortActorOperState_before and dot3adAggPortActorOperState_after.)

Anyway, I'm wanting a clear way to represent the process of overwriting the empty string in variables -- if you have suggestions, plse let me know.

--sk


In reply to searching for clear ways to overwrite the empty string by Anonymous Monk

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.