Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: getfile( $filename )

by harleypig (Scribe)
on Jul 29, 2005 at 18:11 UTC ( #479495=note: print w/ replies, xml ) Need Help??


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

I do a lot of work for clients who either don't have the ability (or the capability) to install from CPAN or just plain don't trust it (I have no idea why) and refuse to use CPAN modules. I have, on occasion, filed off the serial numbers and used a cpan module in order to get something done quickly but I *really* prefer not to do that.

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.

Harley J Pig


Comment on Re^2: getfile( $filename )
Re^3: getfile( $filename )
by QM (Vicar) on Aug 03, 2005 at 20:25 UTC
    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

      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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-07-26 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls