|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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.
|
|
#5
|
||||
|
||||
|
Sorry to be so blunt, incidentally, but sheesh. Can I just give you $20 out of my wallet while I'm at it?
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Perl help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|