If you have any sort of unix system (or any version of unix tools for windows), look up the shell command called "split" (not the perl function of the same name). The unix "split" command does what you want. (And there is a perl version of that already available here:
Perl Power Tools.)
If you want to reinvent the split command again for yourself, you don't really need IO::File for that. In its most basic form, it's just a matter of opening "file.name", for input, opening "file.name.1" for output, then reading and writing a line at a time, incrementing a line counter as you go. When you've done N lines, close "file.name.1", open "file.name.2" for output, reset your line counter, and continue. When there's no more input, you're done.
update: Looking at your question again, I wonder if maybe I missed your point, but for the task you describe, it strikes me that the approach you're trying to take is ill-advised at best, because it involves loading all of a potentially large file into memory at once, and that is completely unnecessary for this task.
Perhaps you have some other reason for wanting to learn how to use IO::File, and if so, tell us about that. But don't implement file splitting this way (in the manner suggested in the OP).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.