|
|
| Perl-Sensitive Sunglasses | |
| PerlMonks |
Re: Split a file based on columnby Kenosis (Deacon) |
| on Jan 16, 2013 at 20:43 UTC ( #1013643=note: print w/ replies, xml ) | Need Help?? |
|
Although your data's a good candidate for a CSV parsing module, perhaps the following will assist:
Usage: perl scriptName.pl sample_1.txt The regex captures the value in the second column, and that's used later in creating the file name. The file's opened for appending, and the line's written to it. Since a lexically-scoped file handle is used, the file's automatically closed at the end of the if code block.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||