I would think the answer to your question:
Anyone care to tell me why this code is dangerous?
would be situational. I can think of a situation where it might be dangerous, but can't say whether it's dangerous to you.
An example of where it's dangerous is where the undef is intended in the defined interface to be meaningful. What if your args are:
@args = ( qw/fee fie foe fum/, func_that_returns_undef_for_error(), 1.
+.3 );
Then you'd be masking errors by fixing up the undefs instead of checking for them and handling them (though I suppose converting to '' might be a way to handle them).
Anyway, just brainstorming here. I think in the right situation you have a good idea.
Update: I was just thinking that if you're "messing" with the value so that you can present undef in output, perhaps you're looking to write a string_maybe_undef() function?
sub string_maybe_undef {
$_ ? $_ : ''
}
then you could
print string_maybe_undef($_).": '".string_maybe_undef($_[$_])."'\n" fo
+reach 0..$#_;
without actually messing with @_.
#my sig used to say 'I humbly seek wisdom. '. Now it says:
use strict;
use warnings;
I humbly seek wisdom.
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.