this is a style question, i guess. I'd love to know of better ways to do the following:
$a = 'text';
$b = $a ? $a : '';
$c = $a->{KEY} ? \$a->{KEY} : 0;
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
$abcdefghijklmnopqrstuvwxyz = 'text';
$d = $abcdefghijklmnopqrstuvwxyz ? $_ : 0;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.