Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 21st, 2004, 01:23 AM
tony_ucdavis tony_ucdavis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 tony_ucdavis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Perl help

Hi all,
I need help to write a perl script to do

I have a file name: netlist.txt Inside of this file I have:

net R C

b 10.2 2
a 1 4
c 4 6

I want to write a sort_col procedule so it can sort net or R or C.

The command to run would be:

sort_col netlist.txt <net|R|C>

When I select net option then the new netlist.txt file would be

net R C
a 1 4
b 10.2 2
c 4 6

When I select R option then it will sort from small number to big number. For example

sort_col netlist.txt R

net R C
a 1 4
c 4 6
b 10.2 2

Reply With Quote
  #2  
Old July 21st, 2004, 07:41 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
This sounds suspiciously like a homework assignment, so I'm not going to give you any code, but I'd consider doing something like iterating over the lines of the file and building a hash whose keys are the values of the columns being sorted on and whose values are arrays representing the values per line. Then you just sort by the hash keys and print out the rows by referencing the hash values in the sorted order.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old July 21st, 2004, 04:29 PM
tony_ucdavis tony_ucdavis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 tony_ucdavis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help

Hi,

This is not a homework question. This is a interview question that I do not know how to answere. I am not good in perl. If you can please write me a script for this.

Thanks,
Tony

Reply With Quote
  #4  
Old July 21st, 2004, 04:58 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Heh, if it's an interview question, I'm sure not going to give you the code. The whole point of such a question is to determine whether you can solve a problem by developing a logical solution and implement it by looking up some very basic tools in an unfamiliar language. If you can't do this, you're not qualified for the job, and I'm not going to help you sabotage your prospective employer. I've gone too far by solving the problem for you and leaving you only to figure out how to implement it. Five minutes at perl.com and 15 lines of code and you're done. Wish I could get a dev job that easily.

Reply With Quote
  #5  
Old July 21st, 2004, 04:59 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Sorry to be so blunt, incidentally, but sheesh. Can I just give you $20 out of my wallet while I'm at it?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Perl help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT