Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Messing with @_

by goibhniu (Hermit)
on May 30, 2008 at 14:23 UTC ( #689222=note: print w/ replies, xml ) Need Help??


in reply to Messing with @_

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.


Comment on Re: Messing with @_
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://689222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2014-07-25 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (172 votes), past polls