/ / perché la funzione map cambia il valore della matrice di input in perl? - matrici, perl, mappa

perché la funzione map cambia il valore della matrice di input in perl? - matrici, perl, mappa

perché la funzione map cambia il valore della matrice di input in perl? Illustrare,

#!/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

Ma questa stampa

 $perl findPalindrome.pl

suhraa

suhraa

Perché l'array originale è stato modificato?

risposte:

4 per risposta № 1

Perché l'hai chiesto modificando $_.

Tu vuoi

my @reverse_words = map { scalar reverse $_ } @words;