Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Why would there be this difference and what's wrong with my foreach??#!/usr/bin/perl -w use strict; use YAML::XS; my %all; open(INPUT,"<coconet.dat") || die "Can't open coconet.dat"; while (<INPUT>) { if ($_ =~ /^#/) { next } my ($src, $dest, $bytes) = split; $all{$src}{$dest}+=$bytes; } close(INPUT); my @reflist = sort { ${$$b}[2] <=> ${$$a}[2] } map \&buildlist($_), ke +ys %all; foreach my $ref (@reflist) { print "${$$ref}[0] ${$$ref}[2]\n"; my @tmp=@{$$ref}[3]; #HERE foreach my $line (@tmp) { print "\t$line\n" } print Dump @tmp; } sub buildlist { my $site = $_; my @tmp; $tmp[0]=$site; $tmp[1]=\%{$all{$site}}; foreach (keys %{$tmp[1]}) { $tmp[2]+=${$tmp[1]}{$_} } @{$tmp[3]} = sort { ${$tmp[1]}{$b} <=> ${$tmp[1]}{$a} } keys %{$tm +p[1]}; return \@tmp; # 0=site name, 1=hash ref, 2=total bytes, 3=sorted + dest refs }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: array reference madness
by almut (Canon) on Mar 14, 2009 at 21:35 UTC | |
by Porculus (Hermit) on Mar 14, 2009 at 21:44 UTC | |
by Anonymous Monk on Mar 14, 2009 at 22:42 UTC | |
by Anonymous Monk on Mar 15, 2009 at 07:03 UTC | |
by halfcountplus (Hermit) on Mar 15, 2009 at 02:08 UTC | |
by halfcountplus (Hermit) on Mar 15, 2009 at 02:34 UTC |