Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^5: Perl::Critic says don't modify $_ in list functions and other things

by jcb (Parson)
on Jul 12, 2020 at 03:20 UTC ( [id://11119195]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Perl::Critic says don't modify $_ in list functions and other things
in thread Perl::Critic says don't modify $_ in list functions and other things

Fair enough; but her signature block still said that her Web host was on 5.8.8 when she posted the question and she did not clarify here until after we had had that discussion.

While our questioner may no longer need to be concerned about that detail, the issue is still a concern for module authors (and really only module authors — scripts can simply avoid aliasing $_ to read-only values when calling such "sensitive" routines) targeting backwards compatibility to perl versions before 5.14, and the workaround works in later versions, albeit with the caveat that you must collect your arguments into lexicals before localizing *_ or only use them again after exiting the block in which *_ was localized. I generally use the my $foo = shift; my $bar = shift; idiom to convert arguments to independent variables instead of leaving them as aliases, so localizing *_ is not a problem — @_ is empty well before that point.

Replies are listed 'Best First'.
Re^6: Perl::Critic says don't modify $_ in list functions and other things
by haukex (Archbishop) on Jul 12, 2020 at 05:58 UTC

    All true. Your initial post didn't mention the caveat that @_ gets localized or that the local *_ workaround is only needed for compatibility with Perls older than 5.14 (2011), so it's good this got cleared up.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2024-04-18 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found