in reply to Re^2: getfile( $filename )
in thread getfile( $filename )

Also, if the file is too big to be read entirely into memory then reading the entire file in one shot isn't a good idea.
Then when you file off the serial numbers, you can add an optional parameter for chunk size, and convert the function to an iterator. Make a module version and put it on CPAN for everyone else (unless there's already one there?)

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^4: getfile( $filename )
by harleypig (Monk) on Aug 06, 2005 at 16:04 UTC
    Well, File::Slurp purpose is to read the entire file, so that module itself is wrong for large files. The best I've come up with in that case is something along the lines of
    my $FH = IO::File->new ... until ( $FH->eof ) { my $chunk = $FH->read( ... ) # process $chunk }
    which doesn't really lend itself to modularization because the processing is always different.
    Harley J Pig
      Then pass in a function reference -- something like this:
      sub chunk_at_a_time { my $FH = IO::File->new ... my $func_ref = shift; my @func_args = @_; until ( $FH->eof ) { &{$func_ref}(@func_args); } } ... My_Module::chunk_at_a_time( @file_args, \&some_sub_name, @sub_args);
      (I dashed this off quick -- the syntax may be wrong, but you get the idea.)

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of