×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

print and display values

print and display values

print and display values

(OP)
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.

RE: print and display values

CODE --> 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";
  }
} 

http://www.xcalcs.com : Online engineering calculations
http://www.megamag.it : Magnetic brakes for fun rides
http://www.levitans.com : Air bearing pads

RE: print and display values

(OP)
Thanks prex1. Made a few tweaks and got it to work.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close