I'm trying to sort a shopping cart basket on the item numbers. The basket is stored in a hash. There is a hashref called %{$main::global->{cart}} that Data::Dumper prints out like so:
$VAR1 = { '1' => '1 1 SL-8206 73.15 Label 8.25" x 6" 0.8 73.15 ', '3' => '3 1 WR-9253 13.98 Label - 3" x 9" 0.5 13.98 ', '2' => '2 1 APT-46V 96.43 4"x6" Label, hook 1.8 96.43 ' }; I would like to grab the item numbers, i.e. SL-8206, to sort the cart on. Could someone point me to something to read up on this? What is the above actually? It looks to me like a hash of hashes of arrays(?). I thought that converting it into an array would help, like so: my $n = keys($main::global->{cart}); my @cart_lineitems = @{$main::global->{cart}}{0 .. $n}; but dumping the output: print {$tracelog_fh} Dumper($cart_lineitems[0]); print {$tracelog_fh} Dumper($cart_lineitems[1]); print {$tracelog_fh} Dumper($cart_lineitems[2]); print {$tracelog_fh} Dumper($cart_lineitems[3]); gives me this: $VAR1 = ''; $VAR1 = '1 1 SL-8206 73.15 Label 8.25" x 6" 0.8 73.15 '; $VAR1 = '2 1 APT-46V 13.98 Label - 3" x 9" 1.8 13.98 '; $VAR1 = '3 1 WR-9253 96.43 4"x6" Label, hook 0.5 96.43 '; Why the first one is empty is beyond me, but that's another story. I then tried to grab just the item numbers using both: print {$tracelog_fh} Dumper($cart_lineitems[1][2]); and print {$tracelog_fh} Dumper($main::global->{cart}->{1}->{2}); but they produce these errors: Can't use string ("1 1 SL-8206 73.15 Label "...) as an ARRAY ref while "strict refs" in use Can't use string ("1 1 SL-8206 73.15 Label "...) as an HASH ref while "strict refs" in use Anyway, maybe I'm going about this the wrong way. I know enough just to be dangerous at this point. The bottom line is, how would I go about grabbing the item numbers from the original hashref so that I can sort the cart on them? I'm over my head with this one, so any pointers would be extremely helpful. I'm reading about references in the "Beginning Perl" book, but so far the light hasn't come on. Thanks, Marc -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/