Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Is undef list assignment a no-op?

by anonymized user 468275 (Curate)
on Mar 25, 2011 at 11:26 UTC ( [id://895451]=note: print w/replies, xml ) Need Help??


in reply to Is undef list assignment a no-op?

Although, you don't actually say what you are trying to do here. For example, if the idea is to remove the first parameter for the purposes of the subroutine, it is more normal just to shift it out and normal ways are more maintainable.

One world, one people

Replies are listed 'Best First'.
Re^2: Is undef list assignment a no-op?
by ELISHEVA (Prior) on Mar 25, 2011 at 12:01 UTC

    It is more normal just to shift it out and normal ways are more maintainable.

    I can respect that it isn't a style you feel comfortable with or are familiar with, but I wouldn't go so far as to call it unusual or abnormal.

    For one, using undef as a placeholder in a list on the left hand of an assignment is a perfectly valid use of Perl syntax. No less than Larry Wall documents its usage in the book Programming Perl (p. 819). Lest one relegate this to some ancient deprecated version of Perl, this usage is also documented even today in undef.

    For another, the use of undef in a list preserves the order of parameters without all the visual noise created by shift statements. One might argue that is is more self-documenting and hence more maintainable.

    Finally, and this is probably most important, shifting parameters out of @_ can make debugging more difficult. If you die and need a stack trace, the shifted out parameters will sometimes display as "undef" being passed to your function call, even though the actual value passed into the function call was absolutely not undef.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-23 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found