in reply to Hash sorting

Assuming you want to sort the data by the key, the idiom you're probably looking for is something like:
my %hash; # use the hash like normal - perl will keep it in whatever # order is the most useful for the runtime foreach my $key (sort keys %hash) { print $hash{$key}; }
Unless your hash is huge (like, tens of thousands of keys), it will almost definately be faster to sort the keys each time you want to access it rather than keep a tied hash (or some other custom datatype) in the sort order that you want.

Replies are listed 'Best First'.
Re^2: Hash sorting
by pickledegg (Novice) on May 15, 2006 at 08:19 UTC
    Thanks, printing it out when needed will do just fine,
    however I need to print both the key names and values.
    Apologies as I'm new to perl.
      however I need to print both the key names and values

      Then print both :)

      foreach my $key (sort keys %hash) { print "$key : $hash{$key}\n"; }

      Update: typo fixed. Thanks to johngg for pointing it out.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        ITYM print "$key : $hash{$key}\n";

        Cheers,

        JohnGG

Re^2: Hash sorting
by pickledegg (Novice) on May 15, 2006 at 09:00 UTC
    Got it!

    Thanks for your patience :)