nmerriweather has asked for the wisdom of the Perl Monks concerning the following question:
basically, I just want to see if a variable is assigned a value and, if so, keep that value. if not, i'd like to set it to a default value (in case $b, an empty string). In case $c, i'm checking a key in an object, and returning a ref if it exists. I'm wondering if there's another way to write that, or approach that, that is more efficient/clean/better regarded.. i was wondering if there were something like - so i could save typing for the repeat of the var when the names are long$a = 'text'; $b = $a ? $a : ''; $c = $a->{KEY} ? \$a->{KEY} : 0;
$abcdefghijklmnopqrstuvwxyz = 'text'; $d = $abcdefghijklmnopqrstuvwxyz ? $_ : 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: check for existing value, else set to default
by saintmike (Vicar) on Apr 26, 2004 at 06:08 UTC | |
by PodMaster (Abbot) on Apr 26, 2004 at 06:37 UTC | |
|
Re: check for existing value, else set to default
by tkil (Monk) on Apr 26, 2004 at 06:54 UTC | |
|
Re: check for existing value, else set to default
by pbeckingham (Parson) on Apr 26, 2004 at 04:54 UTC | |
by waswas-fng (Curate) on Apr 26, 2004 at 06:03 UTC | |
|
Re: check for existing value, else set to default
by ph0enix (Friar) on Apr 26, 2004 at 10:05 UTC | |
|
Re: check for existing value, else set to default
by tinita (Parson) on Apr 26, 2004 at 10:36 UTC |