Tuesday, October 13, 2009

Push HASH into Array in Perl

Kawan yg bertanyakan Perl + AD bertanyakan soalan ini.. bagaimana nak bermain dgn perl array. lebih tepat sekali, memasukkan nilai HASH ke dlm ARRAY utk digunakan kemudian nanti.

contoh disini:

#define testing var
my %h = (
 1=>'k',
 2=>'l'
);

my @a = qw(
 a
 b
 c
);

#push hash to array
push @a, \%h;

#processing array
foreach my $insidea(@a){
 print "- $insidea\n"; 
 foreach my $insideh(keys %{$insidea}){
  print " ->${$insidea}{$insideh}\n";
 }  
}

No comments: