I have the same problem as seen
here. I need to split files according to size, but the splits can only happen on "\n" new lines. So the size can be a little more or less, but it can only be split on a newline.
I'd like to create a module to do this... maybe File::Split::More or File::Split::Qualifier or File::Split::ApproxSize?
What I was thinking was to have an object where it is created with the output directory, the input file, and some options. The options would be the minimum size or maximum file size and the values to split on. The value to split on would be the acceptable location split a file on at the location closest to the file size.
Any comments would be apprecieated....
Here's an example:
use File::Split::More;
my $output_dir = '/tmp';
my $split_file = '/home/me/input.txt';
my $split_rx = File::Split::More->new(
out_dir => $output_dir,
in_file => $split_file,
min_size => 2147483648, # new file size in bytes
split_on_regex => qr{\n},
auto_die => 0,
);
my $split_string = File::Split::More->new(
out_dir => $output_dir,
in_file => $split_file,
min_size => 2147483648, # new file size in bytes
split_on_string => "\n",
);
# do the split
$split_rx->split or die "Can't split file: $!\n";
# get list of new split file names
my @split_files = $split_rx->split_files
# get list of file handles
my @split_file_handles = $split_rx->split_file_handles;
# get list of tie::files
my @split_tie_files = $split_rx->split_tie_files;
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.