[26655] in Perl-Users-Digest
Perl-Users Digest, Issue: 8762 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 14 14:05:34 2005
Date: Wed, 14 Dec 2005 11:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 14 Dec 2005 Volume: 10 Number: 8762
Today's topics:
Sorting a hash containing a hash of hashes <whoever@whereever.com>
Re: Sorting a hash containing a hash of hashes <whoever@whereever.com>
Re: Sorting a hash containing a hash of hashes <Ian.Stuart@ed.ac.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 14 Dec 2005 14:29:35 -0000
From: "IanW" <whoever@whereever.com>
Subject: Sorting a hash containing a hash of hashes
Message-Id: <dnpa8f$kdm$1@blackmamba.itd.rl.ac.uk>
I have a hash arrangement that is used to store data like this:
$hash{directory}{filename}{size}
I want to sort the files in a directory by size before listing them. I
thought I could do it like this ($dir contains the current directory):
foreach my $f (sort { $filehash{$dir}{$a}{size} <=>
$filehash{$dir}{$b}{size} } keys %{ $filehash{$dir} }) { }
However that doesn't seem to work.. I have to confess to still not having
got my head round data structures in Perl, so it may be something obvious
but please put me out of my misery anyway.
Thanks
Ian
------------------------------
Date: Wed, 14 Dec 2005 14:54:19 -0000
From: "IanW" <whoever@whereever.com>
Subject: Re: Sorting a hash containing a hash of hashes
Message-Id: <dnpbmr$kuv$1@blackmamba.itd.rl.ac.uk>
hmmm I think that may actually work and it's something else in my code that
isn't
"IanW" <whoever@whereever.com> wrote in message
news:dnpa8f$kdm$1@blackmamba.itd.rl.ac.uk...
>I have a hash arrangement that is used to store data like this:
>
> $hash{directory}{filename}{size}
>
> I want to sort the files in a directory by size before listing them. I
> thought I could do it like this ($dir contains the current directory):
>
> foreach my $f (sort { $filehash{$dir}{$a}{size} <=>
> $filehash{$dir}{$b}{size} } keys %{ $filehash{$dir} }) { }
>
> However that doesn't seem to work.. I have to confess to still not having
> got my head round data structures in Perl, so it may be something obvious
> but please put me out of my misery anyway.
>
> Thanks
> Ian
>
------------------------------
Date: Wed, 14 Dec 2005 15:02:30 +0000
From: Ian Stuart <Ian.Stuart@ed.ac.uk>
Subject: Re: Sorting a hash containing a hash of hashes
Message-Id: <dnpc66$792$1@scotsman.ed.ac.uk>
IanW wrote:
> hmmm I think that may actually work and it's something else in my code that
> isn't
>
> "IanW" <whoever@whereever.com> wrote in message
> news:dnpa8f$kdm$1@blackmamba.itd.rl.ac.uk...
>
>>I have a hash arrangement that is used to store data like this:
>>
>>$hash{directory}{filename}{size}
>>
>>I want to sort the files in a directory by size before listing them. I
>>thought I could do it like this ($dir contains the current directory):
>>
>>foreach my $f (sort { $filehash{$dir}{$a}{size} <=>
>>$filehash{$dir}{$b}{size} } keys %{ $filehash{$dir} }) { }
>>
>>However that doesn't seem to work.. I have to confess to still not having
>>got my head round data structures in Perl, so it may be something obvious
>>but please put me out of my misery anyway.
I would have expected your sort to work...
You can always do a test by getting Data::Dumper to spit out the list:
if ($debug) {
@f = sort {
$filehash{$dir}{$a}{size}
<=>
$filehash{$dir}{$b}{size}
} keys %{ $filehash{$dir} }
warn "Dumper @f";
}
Just a thought....
--
Ian, Perl Laghu
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8762
***************************************