Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching for clear ways to overwrite the empty string
by Athanasius (Archbishop) on Apr 19, 2016 at 13:00 UTC | |
|
Re: searching for clear ways to overwrite the empty string
by haukex (Archbishop) on Apr 19, 2016 at 13:02 UTC | |
|
Re: searching for clear ways to overwrite the empty string
by Your Mother (Archbishop) on Apr 19, 2016 at 12:49 UTC | |
|
Re: searching for clear ways to overwrite the empty string
by Eily (Monsignor) on Apr 19, 2016 at 13:03 UTC | |
|
Re: searching for clear ways to overwrite the empty string
by Anonymous Monk on Apr 19, 2016 at 17:08 UTC | |
by graff (Chancellor) on Apr 20, 2016 at 00:38 UTC | |
by Anonymous Monk on Apr 20, 2016 at 00:54 UTC |