Date: 11 Jul 2001 20:15:47 GMT From: ctcgag@hotmail.com Subject: Re: Data structures question. Message-Id: <20010711161546.494$e0@newsreader.com> garry_short@hotmail.com (Garry) wrote: > Hello. > > I'm trying to work out one of two things, assuming either is possible. Of course they are. > The first option is a 2d array, 9 columns wide by 10k+ rows deep. OK, I'll assume that's @x[$col][$row] > Is > it possible to sort the array by the nth row? I'll assume you mean $nth column, just because that's the way I think of it, and I'm pretty sure that's what you meant anyway. > If so, could anyone give > me some pointers on how to do it? assuming that you want to sort text (rather than numbers), here's a way: @index = sort { $x[$nth][$a] cmp $x[$nth][$b] } (0..$#x); @sortedx= @x(@index); You can chain together to get rid of the @index variable if you want. It's there for pedagogical poirposes only. > Better still, can I sort that array by multiple columns, as per Excel? @index = sort { $x[$nth1][$a] cmp $x[$nth1][$b] || $x[$nth2][$a] cmp $x[$nth2][$b] || $x[$nth3][$a] cmp $x[$nth3][$b] } (0..$#x); Here, you only look at the $nth3 column if both $nth2 and $nth1 have already compared equal. > If so, does anyone what's the maximum number of columns I can sort by? Depends on where/when your computer pukes. Xho > -- > > Assuming that's not possible, has anyone got any suggestions on > implementing the following data structure : > > array of (unique SRC_IP, > array of (unique SRC_PORT, > array of (unique DEST_IP, > array of (unique DEST_PORT, > array of (unique PROTOCOL, > array of (unique DATE, > array of (unique TIME, > array of (TYPE, CODE) > ) > ) > ) > ) > ) > ) > ) I would suggest not implementing it. Or at least implementing it as chained hashes rather than chained arrays. Xho -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service