Here's the case of taking a reference to the same memory location
again and again:
- # Either without strict or having an outer-scope my @array; declaration.
+ # Either without strict or having an outer-scope my @array;
+ # declaration.
for my $i (1..10) {
@array = somefunc($i);
broken code fragments:
X<[]> X<{}>
- # Either without strict or having an outer-scope my @array; declaration.
+ # Either without strict or having an outer-scope my @array;
+ # declaration.
for my $i (1..10) {
@array = somefunc($i);
Note that this will produce something similar, but it's
much harder to read:
- # Either without strict or having an outer-scope my @array; declaration.
+ # Either without strict or having an outer-scope my @array;
+ # declaration.
for my $i (1..10) {
@array = 0 .. $i;
@{$AoA[$i]} = @array;
In summary:
- $AoA[$i] = [ @array ]; # usually best
- $AoA[$i] = \@array; # perilous; just how my() was that array?
- @{ $AoA[$i] } = @array; # way too tricky for most programmers
+ $AoA[$i] = [ @array ]; # usually best
+ $AoA[$i] = \@array; # perilous; just how my() was that array?
+ @{ $AoA[$i] } = @array; # way too tricky for most programmers
=head1 CAVEAT ON PRECEDENCE
# print the whole thing sorted by number of members
- foreach $family ( sort { keys %{$HoH{$b}} <=> keys %{$HoH{$a}} } keys %HoH ) {
+ foreach $family ( sort { keys %{$HoH{$b}} <=> keys %{$HoH{$a}} }
+ keys %HoH )
+ {
print "$family: { ";
for $role ( sort keys %{ $HoH{$family} } ) {
print "$role=$HoH{$family}{$role} ";
for ( qw(lead wife son daughter pal pet) ) { $rank{$_} = ++$i }
# now print the whole thing sorted by number of members
- foreach $family ( sort { keys %{ $HoH{$b} } <=> keys %{ $HoH{$a} } } keys %HoH ) {
+ foreach $family ( sort { keys %{ $HoH{$b} } <=> keys %{ $HoH{$a} } }
+ keys %HoH )
+ {
print "$family: { ";
# and print these according to rank order
- for $role ( sort { $rank{$a} <=> $rank{$b} } keys %{ $HoH{$family} } ) {
+ for $role ( sort { $rank{$a} <=> $rank{$b} }
+ keys %{ $HoH{$family} } )
+ {
print "$role=$HoH{$family}{$role} ";
}
print "}\n";