the open curly brace goes after the sort
my @array = (
{ data => 'blah', filename => 'this.txt' },
{ data => 'blah', filename => 'that.txt' },
{ data => 'blah', filename => 'some.txt' },
{ data => 'blah', filename => 'blah.txt' },
{ data => 'blah', filename => 'blarg.txt' },
{ data => 'blah', filename => 'foo.txt' },
{ data => 'blah', filename => 'bar.txt' },
{ data => 'blah', filename => 'baz.txt' },
{ data => 'blah', filename => 'bah.txt' },
{ data => 'blah', filename => 'fun.txt' }
);
my @sorted = sort { $a->{'filename'} cmp $b->{'filename'} } @array;
print "$_->{'filename'}\n" foreach @sorted;
Peter Guzis
Web Administrator, Sr.
ENCAD, Inc.
email: [EMAIL PROTECTED]
www.encad.com
-----Original Message-----
From: Purcell, Scott [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 27, 2001 7:24 AM
To: '[EMAIL PROTECTED]'
Subject: Help With Sorting A RefToAOH
Hello,
I have a array of hashes created in my code. Each hash has 5 fields. I wish
to sort on the filename in each hash as I go through the array of hashes.
But as I use more and more refeences, I actually have a reference to an
array of hashes. So when I am trying to sort these, I am getting off-course.
I have the Cookbook, but see no examples of how to do sort this animal.
Below, I show what I have been trying to do, but it does not yet work (the
sort line) and below that is the format in which works, and prints, but of
course is not in a sorted (cmp alphanumeric) sort order.
My data is currently in this variable: $refToAOH (but remember, this is a
reference to the real Array of Hashes).
Thanks
Scott
PS, if it is in the camel or advanced, please let me know, but I could not
find it there, and I will earmark it.
################### rough code below ####################################
@{$sortedRefToAOH} = { sort $a->{FILENAME} cmp $b->{FILENAME} }
@{$refToAOH};
# foreach my $n(0 .. $#{$refToAOH}) {
foreach my $n(0 .. $#{$sortedRefToAOH}) {
print "${$refToAOH}[$n]->{FILENAME}<br>\n";
print "${$refToAOH}[$n]->{DATABASE_NAME}<br>\n";
print "${$refToAOH}[$n]->{DATABASE_PATH}<br>\n";
}
Scott Purcell
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users