 |
|
Home:
Perl Programming Help:
Intermediate:
Sorting Chunks of a file:
Edit Log
|
|

sn0rkl3m4st3r
New User
Sep 1, 2011, 6:15 AM
Views: 3664
|
Hi, I'm attempting to sort a file based on a few criterium. I have a file that has a similar structure to the following: #*---------------- GRAPH: <graphname> stuff #*---------------- GRAPH: <graphname> stuff #*---------------- I need to put these graph chunks in alphabetical order (based on the graph name) with the exact same file structure. Does anyone have any ideas? Maybe some resources of problems similar to this? So far I have this...
if (-e $ARGV[0]) { #open file for iteration open(f, $ARGV[0]) or die("Could not open file"); #iterating... $i = 0; @hashes = (); %graph = (); $first = 1; while(f) { #read lines from file $line = readline(f); #check for ##*-------- line #if in the graph section set the hash values #and set the hash in the array if($line =~ m/^#\*+-/) { } else { #print "setting in hash\n"; $inhash = 1; } if($inhash) { $graph{"$linenumber"} = $line; $linenumbers++; } } } else { die("cannot find file"); } close(f); print "@hashes\n"; This is not all my code obviously but it's the basic idea (without all the usage checking). Basically, I've gotten far enough to find the lines that separate the data. Any suggestions would be greatly appreciated! Thanks!
(This post was edited by sn0rkl3m4st3r on Sep 1, 2011, 6:18 AM)
|
|
|
Edit Log:
|
|
Post edited by sn0rkl3m4st3r
(New User) on Sep 1, 2011, 6:16 AM
|
|
Post edited by sn0rkl3m4st3r
(New User) on Sep 1, 2011, 6:17 AM
|
|
Post edited by sn0rkl3m4st3r
(New User) on Sep 1, 2011, 6:18 AM
|
|
|  |