Perl - Transforming an anonymous array -


i can manipulate single array element , add reference array value in hash. easy. example, achieves desired result:

# split line array @array = split;  # convert second element hex dec $array[1] = hex($array[1]);  # add array hash $hash{$name}{ ++$count{$name} } = \@array; 

my question: possible same thing using anonymous array? can close doing following:

$hash{$name}{ ++$count{$name} } = [ split ]; 

however, doesn't manipulate second index (convert hex dec) of anonymous array. if can done, how?

what asking this

my $array = [ split ];  $array->[1] = hex($array->[1]);  $hash{$name}{ ++$count{$name} } = $array; 

but may not mean.

also, rather using sequential numbered hash keys better off using hash of arrays, this

my $array = [ split ];  $array->[1] = hex($array->[1]);  push @{ $hash{$name} }, $array; 

you need way access array want modify, modify after pushing onto hash, this:

push @{ $hash{$name} }, [split]; $hash{$name}[-1][1] = hex($hash{$name}[-1][1]); 

although that's not nice. or could

push @{ $hash{$name} }, {     @array = [split];     $array[1] = hex($array[1]);     \@array; }; 

or even

for ([split]) {     $_->[1] = hex($_->[1]);     push @{ $hash{$name} }, $_; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -