Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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]
[LanX]: darn. .. I wanted to see Marine and Melonchon go to next round, just for fun xD
[Discipulus]: LA use Perl: traversing a dir tree is simple; foreach file mp3 $sec+= use Mp3::Info
[Lady_Aleena]: Discipulus, I was able to get the sum of the seconds on the command line using awk. Then I ran the result through a perl script and got the result. It came bach with 4 days, 9 hours, 56 minutes, 43 seconds.
[Lady_Aleena]: s/bach/back/;
[Discipulus]: gired anyway is the intermediate state between hired and fired (and vice versa;)
[Lady_Aleena]: Discipuluis, I don't know if I want to fight with File::Find. File::Find and I are not friends.
[Discipulus]: 4 day Bach is too muche even for me
[Discipulus]: LA you know who is paco?
[Lady_Aleena]: Disc, nope.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-04-23 20:35 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.