in reply to Re^4: Spliting file + removing column
in thread Spliting file + removing column

Programs never do work correctly the first few times you try to run them.

My suggestion is to start with my program, then try to make one small change at a time. For instance you might work in steps like these:

  1. Add prints at the end that print out the correct *edges block. (You can go back to my previous suggestion for how to do that.)
  2. Run it. Make sure that this works.
  3. Save this copy somewhere. If you mess up, you don't want to lose this change.
  4. Remove the prints that print out the incorrect edges block.
  5. Run it. Make sure that this works.
  6. Save this copy as well.
  7. Create a second array called vertex_output, and populate it with "$row[0] $row1"; And print it out instead of @vertices for the *vertices block.
  8. Run it. Make sure this works.
  9. Save this. This is your program.
  10. Try running it on your full data set. If it breaks, it should have an error message with a line number with something unexpected. Open up the data file, go to that line number, and see how what is there doesn't match what the program expected to see there.
  11. Try to fix that.
Note that I put a lot of assertions in. This is a very good practice. It is initially frustrating when the program keeps crashing, but when it finally runs it is much more likely to be doing the correct thing.

Note that the most likely way in which your program won't work is that the big assumption that every block contains the the same vertices in the same order will prove to be incorrect. If this is the case, then you'll need a rewrite. My suggestion for how to do that is to go through the data collecting two hashes. One has as keys the vertices, for instance "3 G". The other is %collect in my code above. Then use the first hash to print out the vertices, and the second to print out edges.

Good luck.