|
|
|
good chemistry is complicated, and a little bit messy -LW |
|
| PerlMonks |
Better method to cut columns from delimited fileby stevieb (Hermit) |
| on May 10, 2012 at 04:36 UTC ( #969739=perlquestion: print w/ replies, xml ) | Need Help?? |
|
stevieb has asked for the
wisdom of the Perl Monks concerning the following question:
Helped a fellow Perler with a problem on a lesser Perl site, and am looking for feedback on my code. It's late in the day, and somehow I think this can be written shorter and better, but I can't wrap my head around how at the moment. I'm looking for how to make this code shorter and/or more efficient (examples using modules welcome). The request was to take data like this:
...then print out a sub-selection of columns in the same format so the output was like this (from cols NAME & CITY):
Here is my code that I'm having difficulty thinking about how to make smaller/better (requires perl v5.12+ due to the use of each() on the array):
ps. I've never used any csv-type modules, but I have heard of their use, so if I've overlooked their use for this, feel free to point one out and be harsh on me ;) Update: I should have clarified... in the code above, if I opt to select different column headers (eg ZIP, AGE, NAME as opposed to NAME, CITY), the order is preserved regardless of the column name or the order passed in via the @master_cols array. I'm sorry this wasn't clear originally. It doesn't take away from the quality responses so far though.
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||