Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!ogicse!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: printing assoc array in non-alphabetical order Message-ID: <1991May8.180938.11596@iwarp.intel.com> Date: 8 May 91 18:09:38 GMT References: <46485@bcsaic.UUCP> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 33 In-Reply-To: vince@bcsaic.UUCP (Vince Skahan) In article <46485@bcsaic.UUCP>, vince@bcsaic (Vince Skahan) writes: | %files=("net.jan",1,"net.feb",2,"net.mar",3,"net.apr",4); | foreach $item (sort keys %files) | { | print "$item\n"; | } Gosh. You're closer than you think, perhaps. Try this: %files=("net.jan",1,"net.feb",2,"net.mar",3,"net.apr",4); sub by_files { $files{$a} <=> $files{$b}; # use the spaceship operator } foreach $item (sort by_files keys %files) { print "$item\n"; } But couldn't you also just go: foreach $item ('net.jan', 'net.feb', 'net.mar', 'net.apr') { print "$item, $total1{$item}, $total2{$item}\n" } You don't need to sort the keys if you don't want to! print "Just another Perl hacker," -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/