chinamox has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
I have been reading up on IO::File and I wanted to see if anyone could post or point me towards an example of a program that uses IO::File to split a large file into several smaller files with a set number of lines each.
For example lets say my original file $file has 3200 lines in it. I want to use IO::File to make four new files (titled $file1, $file2, $file3, $file4) and write them in my current directory.
What I have figured out from docs so far:
#!/usr/local/bin/perl -w use strict; use IO::File; #Open and read In File open(IN, '/myfiles/test/file')||die "Can not open '/myfiles/test/file' + :$!\n" while(<IN>){ }; close (IN); #Open file for writing open(OUT, '>', $file)||die "Can not open $file :$!\n"; print OUT "...800Lines of output..."; close(OUT);
As always, thank you for your time and help.
-mox
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::File Question
by ikegami (Patriarch) on Oct 23, 2006 at 04:37 UTC | |
|
Re: IO::File Question
by graff (Chancellor) on Oct 23, 2006 at 03:30 UTC | |
by chinamox (Scribe) on Oct 23, 2006 at 04:07 UTC | |
by ikegami (Patriarch) on Oct 23, 2006 at 06:20 UTC | |
by graff (Chancellor) on Oct 23, 2006 at 05:15 UTC |