I generally do it the tough way :(
############################################### open (CUST, "<$cust") or die "Cant open it :$!"; $newnum = 0; while (<CUST>) { chomp; @data = split /\|/; $newnum++; $hData{$data[1]}{$newnum} = [@data]; # 2 dimensional hash used in case your 2nd element may be same across records } close (CUST); open WRFILE, ">$wrfile"; select (WRFILE); foreach (sort {$a <=> $b} keys %hData) { foreach $inIndex (sort {$a <=> $b} keys %{$hData{$_}}) { print ";", @{$hData{$_}{$inIndex}}, ";", "\n"; } } close (WRFILE); __END__ ################################################# if the file is huge and all the data cannot be stored in the hash for memory shortage, then I would create a temporary file in which the fist element would be be the 2nd element of the original file and then sort on the file and then edit the temporary file to remove the first element. Any better ideas friends?? -----Original Message----- From: Ned Cunningham [mailto:[EMAIL PROTECTED]] Sent: Friday, May 31, 2002 11:27 AM To: 'David T-G'; perl beginners Cc: Ned Cunningham Subject: RE: Printing all elements of an Array except the first? OOPS :-( I wanted to sort the file that I am writing, by the second element in @DATA? Snip open CUST, $cust or die "Cant open it :$!"; open WRFILE, ">$wrfile"; while (defined ($line = <CUST>)) { chomp $line; @data = split(/\|/,$line); $newnum=$newnum+1; printf WRFILE ("0%9d",$newnum); print WRFILE ";", @data, ";"; print WRFILE "\n"; } -----Original Message----- From: David T-G [mailto:[EMAIL PROTECTED]] Sent: Friday, May 31, 2002 11:22 AM To: perl beginners Cc: Ned Cunningham Subject: Re: Printing all elements of an Array except the first? Ned -- ...and then Ned Cunningham said... % % Great, % Now how about sorting on the "new" first element of the array each time I % step through a file??? How about a little more detail? I'm not sure quite what you mean by new; you top-posted instead of providing any contextual reference. Given input of a b c d e f g h i a a a do you want to sort on the b/f/a elements, or something else? If you do, then - do you ever need the first elements, or can you just throw them away at read time and then sort naturally? - is there any reason not to whip up a little sort that's based on that element? In the last case, I envision something about like sort { $a[1] <=> $b[1] } or so... :-D -- David T-G * It's easier to fight for one's principles (play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie (work) [EMAIL PROTECTED] http://www.justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]