in reply to Re^4: Splitting a Blocked file in Round Robin into smaller files
in thread Splitting a Blocked file in Round Robin into smaller files
This assumes that the input filename contains at least one dot. The number will precede the last dot in the input:
#! perl -sw use strict; my $file = $ARGV[0]; my( $prefix, $suffix ) = ( $file =~ m[^(.+)\.([^.]+)] ); open I, '<', $file or die $!; my @outs; open $outs[ $_ ], '>', "$prefix.${_}.$suffix" or die $! for 1 .. 4; my $out = 0; while( <I> ) { print { $outs[ $out+1 ] } $_; if( /^5/ ) { ++$out; $out %= 4; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Splitting a Blocked file in Round Robin into smaller files
by tradersjoe0 (Novice) on Mar 09, 2016 at 17:07 UTC |