This is an interesting approach. Of course my Perl OOP skills have
atrophied, so I have a few questions if you don't mind. 
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> # call new() with named args found in init() to override defaults
> my( $fSpliter ) = Text::FileSplitter->new();

Is Text:: a pre existing class (from CPAN or something) or are we
originating this class?
If this is our own new class, I should have $PERLIB\text\FileSplitter.pm ?

Override defaults like this? 
my( $fSpliter ) = Text::FileSplitter->new( file=>'split.txt',
record_length=>50 );

Thanks 
Jim


> 
> $fSpliter->split();
> 
> print( "done!\n" );

------------------------
> 
> package Text::FileSplitter;
> use strict;
> use IO::File;
> 
> sub new {
>    my($class, %args) = @_;
>    my($self) = bless( { %args }, $class );
>    $self->init();
>    return( $self );
> }
> 
> sub init {
>    my($self) = shift(); my($filehandles) = [];
> 
>    $self->{ file } ||= './splitfile.txt';
>    $self->{ output_prefix } ||= ( ($self->{ file } =~ 
> /(\w+)/) and $1 );
>    $self->{ file_count }  ||= 5;
>    $self->{ record_length }  ||= 10;
> 
>    $self->{ fh } = IO::File->new( "< $self->{ file }" )
>      or die("open $self->{ file }: $!");
> 
>    foreach ( 1 .. $self->{ file_count } ) {
>      push(
>        @{ $filehandles },
>        IO::File->new("> $self->{ output_prefix }.$_")
>      );
>    }
>    $self->{ ofh } = $filehandles;
> 
> }
> 
> sub split {
>    my($self) = shift(); my($buffer);
>    my($counter) = 0;
>    while ( sysread $self->{ fh }, $buffer, $self->{ 
> record_length } ) {
>      $self->{ ofh }[ $counter % $self->{ file_count } 
> ]->print( $buffer );
>      $counter++;
>    }
> }
> 
> HTH
> 
> Todd W.
>
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to