Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: getfile( $filename )

by harleypig (Monk)
on Aug 06, 2005 at 16:04 UTC ( [id://481506]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^5: getfile( $filename )
by QM (Parson) on Aug 07, 2005 at 16:12 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://481506]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-16 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found