Skip Menu |

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 48460
Status: rejected
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: lespea [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Apply issues
I recently ran into this bug while "applying" lc to an array: the values appear to be unchanged. Test case 2 does work but I had expected the first one to as well. #!/usr/bin/perl use strict; use warnings; use List::MoreUtils qw/apply/; my @t = qw/ t T t/; # Apply test cases printf("%s\n", join qq{, }, apply {lc} @t); printf("%s\n", join qq{, }, apply {$_=lc} @t); # Map test case printf("%s\n", join qq{, }, map {lc} @t); OUTPUT: t, T, t t, t, t t, t, t EXPECTED: t, t, t t, t, t t, t, t
This is actually the intended behavior. apply, unlike map, acts on a copy of the input list and $_ is not an alias. Its purpose is to avoid something like this: my @list = map { (my $c = $_) =~ s/foo/bar; $c } @input; With apply, this becomes: my @list = apply { s/foo/bar/ } @input; In particular, the return value of the block is $_ and not the last statement evaluated. Cheers, Tassilo