in reply to How come @_ gets changed here?

G'day pritesh_ugrankar,

Whenever I see code like

&function(...)

it raises a red flag.

Unless you can expand that to

# In the following code, I am aware of the leading ampersand. # I have read, and fully understood, all the implications of # writing the code, as is; having read and completed digested # all information in http://perldoc.perl.org/perlsub.html. # I totally intended that code to be written as is because # ... # ... # ... &function(...)

To understand my code better, refer to "perlsub - Perl subroutines".

Unless you can confidently fill in all of the blanks in the above comments, you've almost certainly done something wrong.

— Ken

Replies are listed 'Best First'.
Re^2: How come @_ gets changed here?
by Anonymous Monk on Jun 10, 2017 at 19:04 UTC
    Not sure what you mean here. Are you complaining about the use of the ampersand with the function call? I usually advise against that too, but in this case the behavior is the same with or without it.

      You raise a valid point and I'm definitely not "complaining" about anything. Like you, I "usually advise against" that usage.

      My intention was to point out, quite unequivocally, that there was a difference between

      &sub(@args)

      and

      sub(@args)

      Reviewing what I originally wrote, it's perhaps not immediately obvious that, without a valid reason for writing

      &sub(@args)

      it would generally be preferable to write

      sub(@args)

      Thankyou for raising this point and providing an opportunity for clarification.

      — Ken

        Well, it can bypass prototype checks, though in this case the sub has no prototype.