http://qs321.pair.com?node_id=11119076


in reply to Re: 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

I hope I’m not being obtuse and about to embarrass myself but…

# Why this? my @b = apply { $_ = uc($_);} @a; # Instead of this, or a more verbose version of it? my @b = map uc, @a;

Replies are listed 'Best First'.
Re^3: Perl::Critic says don't modify $_ in list functions and other things
by AnomalousMonk (Archbishop) on Jul 09, 2020 at 14:34 UTC

    I'll take the liberty of answering for ikegami and guess that
        my @b = apply { $_ = uc($_);} @a;
    is just a quick example of the use of apply put together to be consistent with the preceding code
        my @b = map { $_ = uc($_); $_ } @a;
    which was itself just a quick example put together to demonstrate a particular problem. I'd be very surprised if ikegami suggested it | either for production code.


    Give a man a fish:  <%-{-{-{-<

Re^3: Perl::Critic says don't modify $_ in list functions and other things
by ikegami (Patriarch) on Jul 12, 2020 at 14:40 UTC

    Of course, but the OP isn't actually using $_ = uc($_), and your solution wouldn't help the OP. $_ = uc($_) is just a placeholder for a large block of code that possibly modifies $_.