Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!isi.edu!venera.isi.edu!jas From: jas@ISI.EDU (Jeff Sullivan) Newsgroups: comp.lang.perl Subject: Sortin based on part of an associative array? Message-ID: <17524@venera.isi.edu> Date: 10 Apr 91 23:48:34 GMT Sender: news@isi.edu Distribution: comp Organization: USC-ISI Lines: 38 I have an situation where I'm storing a "structure" of information about various files in a SPLITtable string using an associative array. For example: $Images{"TEST.IMG"} = "120#55#4#GIF" which might mean that the file TEST.IMG is 120x55 pixels, 4 bitplanes deep, and is a GIF format file. What I want to do is write a sort routine that lets me sort the %Images elements by image length or width. Here's what I have: sub bylen { local ($alen, $awid, $adep, $afmt, $blen, $bwid, $bdep, $bfmt); ($alen, $awid, $adep, $afmt) = split('#', $Images{$a}); ($blen, $bwid, $bdep, $bfmt) = split('#', $Images{$b}); $alen cmp $blen; } However, when I try to do this (on MS-PERL PL 18), I get a syntax error at the line containing "$alen cmp $blen;" Why? Can't I do this? Is there a better way? jas -- -------------------------------------------------------------------------- Jeffrey A. Sullivan | Senior Systems Programmer jas@venera.isi.edu | Information Sciences Institute jas@isi.edu | University of Southern California