Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://689222]
and the questions are moot...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2018-06-25 00:46 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.