Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 @_.

use strict;
use warnings;
I humbly seek wisdom.

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2014-12-26 02:03 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (164 votes), past polls