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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print and display values 1

Status
Not open for further replies.

max1x

Programmer
Jan 12, 2005
366
0
0
US
I have not coded for while, so pardon the rustiness.

I have two sets of values being pulled from a DB.
1 cat1
2 cat1
3 cat2
4 cat3
5 cat3
6 cat1
7 cat1

What I need to do is key off of 2nd filed and associate all values fron field 1. The number of values when reach a pre-defined limit should stop and then start in a new line.

OUTPUT:
cat1 1 2
cat1 6 7
cat2 3
cat3 4 5

I've got all the other parts figured out and am stuck on how to make it display as show in the output.

 
Perl:
for(...){
  push @{$set{$key}},$value;
}
for(sort keys%set){
  if(@{$set{$_}}>$limit){
    print"@{$set{$_}}[0..$limit-1]\n";
    print"@{$set{$_}}[$limit..$#{$set{$_}}]\n";
  }else{
    print"@{$set{$_}}\n";
  }
}

: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Thanks prex1. Made a few tweaks and got it to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top