#!/usr/bin/perl -w # Copyright (C) 2004 Mike Irwin <rhythmicus@pobox.com> # This program is free software; you can redistribute it and/or modify + it under # the same terms as Perl itself. # This program comes with ABSOLUTELY NO WARRANTY. # See `perldoc perlartistic'. use strict; use POSIX qw(floor); use constant SPLIT_SIZE => 3996; foreach (@ARGV) { die "$_: $!\n" unless -r; my $size = -s _; next unless $size > 4096; my $last_size = $size % SPLIT_SIZE; my $num_files = floor( $size / SPLIT_SIZE ); $num_files++ if $last_size; my ( $file, $read, $j, $data, $link ); my $width = length($num_files); open OF, "+<$_" or die "$_: $!\n"; for ( my $i = $num_files ; $i > 0 ; $i-- ) { $file = sprintf( "%s.%0*d", $_, $width, $i ); $read = 0; open NF, ">$file" or die "$file: $!\n"; seek OF, -( ( $i == $num_files and $last_size ) ? $last_size : SPLIT_ +SIZE ), 2; while ( $j = read OF, $data, SPLIT_SIZE ) { print NF $data; $read += $j; } print NF "...\n\n<a href=\"$link\">Next Page</a>" if ( $i < $num_files ); close NF; truncate OF, $size -= $read; $link = $file; } close OF; unlink or warn "$_: $!\n"; }

In reply to ipodsplit by rhythmicus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.