Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort multiple fields

Status
Not open for further replies.

ibjdt

Programmer
Nov 25, 2002
63
0
0
thanks to icrf i found an answer i had been searching for hours dealing with sorting multiple fields, but i have a question about the syntax and an unrelated question about another part of my program.

i have a 10 column flatfile db (seperated with ::) that i sort by col 1 then 4 then 2.

i found at

Code:
@doclist = sort {
    (split '::', $a, 2)[0] cmp
    (split '::', $b, 2)[0]
||
    (split '::', $a, 2)[3] cmp
    (split '::', $b, 2)[3]
||
    (split '::', $a, 2)[1] cmp
    (split '::', $b, 2)[1]
  } @doclist;

it works great, but ...$b, 2... what does the ', 2' mean??

****
Now for the other situation that i need critique and suggestions.

my db holds product drawing info in this form......

Code:
drawing1::part1::xx::drawing_location1::xx::xx::xx::xx::xx::xx::xx
drawing1::part1::xx::drawing_location2::xx::xx::xx::xx::xx::xx::xx
drawing1::part2::xx::drawing_location1::xx::xx::xx::xx::xx::xx::xx
drawing1::part3::xx::drawing_location1::xx::xx::xx::xx::xx::xx::xx

when a search is performed, i sort by drawing / location / part so they are re-arranged to
line1
line3
line4
line2

my question is how do i return search listings for only unique occurrances of drawing/location combos. in other words, the items on line 1, 3, 4 are all on drawing1 in location1. so i want to create one search result for that drawing linked to the location.

line 2 has the same drawing number, but it's in a different location so it would be the second search result.

the way i have done it so far (try not to laugh)......

Code:
@results is the sorted db

# COUNTER USED BELOW TO COMPARE FIELDS
  $compcount=0;

  foreach $line (@results) {
    chomp($line);
    @td=split(/::/, $line);

# VARIABLE FOR COMPARING DRAWING NUMBERS BETWEEN LINES
    $compare[$compcount] = $td[0];
# VARIABLE FOR COMPARING LOCATIONS BETWEEN LINES
    $compare2[$compcount] = $td[3];

# KEEP THE DATALINE IF THIS IS FIRST LINE OF DB || DRAWING NOT EQUAL TO DRAWING ON PREVIOUS LINE || DRAWING IS SAME BUT LOCATION ISN'T
    if (($compcount == 0) || (($compare[$compcount]) ne ($compare[$compcount-1])) || ((($compare[$compcount]) eq ($compare[$compcount-1])) && (($compare2[$compcount]) ne ($compare2[$compcount-1])))) { $count++; push @results2, $line };

# GOTO NEXT LINE
      $compcount++;
  }

is there a better way? i hope this is clear enough. if not, please respond and i will answer any questions.

thanks in advance for the help.
 
you should post this question in the perl forum, not the cgi forum. repost the question in the perl forum and red flag this one asking the moderators to delete it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top