¿Por qué la función de mapa cambia el valor de la matriz de entrada en perl? Para ilustrar,
#!/usr/bin/env perl
use strict;
use warnings;
use v5.10;
my @words = <DATA>;
# want to have another array that contains the each word in reverse order
my @reverse_words = map { $_ = scalar reverse $_ } @words;
say $words[0]; # want to check the content of first element of original array
say $reverse_words[0]; # new
__DATA__
aarhus
aaron
ababa
aback
Pero esto imprime
$perl findPalindrome.pl
suhraa
suhraa
¿Por qué se altera la matriz original?
Respuestas
4 para la respuesta № 1Porque lo pedisteis modificando. $_
.
Usted quiere
my @reverse_words = map { scalar reverse $_ } @words;