Perl 要印出 hash 的全部內容, 有以下幾種方法:
- while(my ($key, $val) = each(%hash)) { print "$key $val" }
- %hash = qw / car 600k bike 70k /; print $_ , $hash{$_} , "\n" foreach (keys %hash);
- print "$_ $hash{$_}\n" foreach (keys %hash);
- print "$_ $h{$_}\n" for keys %h;
Perl 印出 Array 的內容:
- print $_."\n" for @a;
- print @a;
- push @a, split for <>; print @a;