in reply to Re: Sorting a Hash Ref
in thread Sorting a Hash Ref

The dates should always remain 2 characters. But I keep running into an error when I run the script.
Can't use string ("57e27be8194bb2332a49a942e7aeafeb") as a HASH ref wh +ile "strict refs" in use at ...
Any ideas on what I'm doing wrong?

Replies are listed 'Best First'.
Re^3: Sorting a Hash Ref
by sauoq (Abbot) on Oct 26, 2005 at 18:23 UTC

    That string, "57e27be8194bb2332a49a942e7aeafeb", is your key (as shown in your original post.) You are trying to use the key itself as a hash ref. You can't do that. You need to look up the hash ref stored in your hash at that key. I.e. you are doing something like $key->{old_file} where you need to be doing something like $yourhash{$key}->{old_file} or possibly $yourhashref->{$key}{old_file}. It's impossible to tell which from your post because you don't show us whether you access your top level hash directly or through a reference.

    -sauoq
    "My two cents aren't worth a dime.";
    
      I guess my understanding of sort leaves much to be desired. Here is the code I am using to build the hash. This below doesn't error but it is not carrying the rest of the data attached with it.
      my %sorted = sort { $patients->{$a}{old_file} cmp $patients->{$b}{old_file} } (keys %{$patients}); my $patients = \%sorted; # or put { } around the sort expression to do it one line.
      or
      sort { $$patients{$a}->{old_file} cmp $$patients{$b}->{old_file} }
      And for some odd reason $patients is no longer a hash ref??
Re^3: Sorting a Hash Ref
by kwaping (Priest) on Oct 26, 2005 at 18:21 UTC
    Well, that is true. What are you not telling us here? That Dumper output doesn't look right. Is that just part of the dump?
      I apologize, yes that is just part of the dump, I cut most of it for space purposes. I thought I still was using the top tier of it though. Here is a copy of the first entry, including the $VAR.
      $VAR1 = { '57e27be8194bb2332a49a942e7aeafeb' => { 'files' => [ { 'file +_type' => 1, 'date +_uploaded' => '2005-09-12', 'file +_name' => 'SOme file PO.tif', 'date +_faxed' => '' }, { 'file +_type' => 2, 'date +_uploaded' => '2005-09-23', 'file +_name' => 'somess 992525 R N.pdf', 'date +_faxed' => '2005-09-23' } ], 'phone' => 'xxx-xxx- +xxxx', 'last_name' => 'Doe +', 'dme_num' => '992525 +', 'old_file' => '2005- +09-12', 'pid' => '57e27be819 +4bb2332a49a942e7aeafeb', 'dme_pid' => '6310b1 +22dad26ec5c6c1c72a15112bb7', 'first_name' => 'Joh +n ' },