In una domanda precedente ho chiesto come inizializzare un hash Perl usando le slice. E 'fatto così:Come utilizzare una slice hash per inizializzare un hash memorizzato in una struttura dati?
my %hash =();
my @fields = ('currency_symbol', 'currency_name');
my @array = ('BRL','Real');
@hash{@fields} = @array;
Ora immaginiamo un hash più complesso, ed ecco come viene inizializzato:
my %hash =();
my $iso = 'BR';
$hash->{$iso}->{currency_symbol} = 'BRL';
$hash->{$iso}->{currency_name} = 'Real';
print Dumper($hash);
Il risultato è il seguente:
$VAR1 = {
'BR' => {
'currency_symbol' => 'BRL',
'currency_name' => 'Real'
}
};
Ora la domanda sarebbe: come inizializzare questo particolare hash usando il metodo splice?
ti ho urtato up . Non ho idea del motivo per cui qualcuno ti ha urtato senza una spiegazione - diamine, il tuo codice è persino * formattato *. – Axeman
Grazie. Non me ne sono nemmeno accorto. Sto iniziando ad amare questo sito. – emx