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

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

by choroba (Cardinal)
on Jul 09, 2020 at 05:37 UTC ( [id://11119065]=note: print w/replies, xml ) Need Help??


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

Sometimes, no loop is needed at all:
chomp( my @list = <$fh> );

When using readline, it's probably not so serious, as you aren't changing the original array in place at the same time.

The /r is useful when you want to keep the original:

my @ids = map s/ /_/gr, grep defined, @base;

When you want to modify the original array, use "for" instead.

for (@$list) { if (ref) { ... } else { $_ = ...; } }
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Perl::Critic says don't modify $_ in list functions and other things
by hippo (Bishop) on Jul 09, 2020 at 08:33 UTC
    The /r is useful when you want to keep the original

    It is indeed useful and thanks for mentioning it (++). For some reason the fact that it exists never seems to stick with me! However, in Lady_Aleena's case it might not be an option because her sig says

    my perl versions are 5.28.1 local and 5.8.8 on web host.

    and /r only came in at 5.13.2 (according to perlver).

    As an even further aside it's a bit surprising to find anyone offering 5.8.8 as part of a service today. I am not aware of any O/S still shipping that as standard.

      As an even further aside it's a bit surprising to find anyone offering 5.8.8 as part of a service today. I am not aware of any O/S still shipping that as standard.

      That's what I was thinking...
      I'm considering upgrading from shared hosting to VPS purely so I can upgrade from 5.16.003 to something a bit more modern. Being stuck with 5.8.8 seems a bit dire.

        Your own VPS is so cheap these days, and allows the freedom to leave the past where it belongs. I'm sure you'll only have a positive experience moving forwards with this.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found