develooper Front page | perl.perl5.porters | Postings from October 2003

Re: new slurp module

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
October 23, 2003 02:04
Subject:
Re: new slurp module
Message ID:
20031023090325.GC3953@localhost.comcast.net
On Thu, Oct 23, 2003 at 04:30:42AM -0400, Uri Guttman wrote:
> i would like to nail down a namespace before i release it to cpan and
> publish the article. one suggestion was File::Atomic or its variant
> IO::File::Atomic. slurp isn't a proper name since the module also can
> write (spew? burp?) out files in one call. any naming ideas are
> welcome. also any i welcome any general feedback on the article, the
> code, or the pod before it all goes public.

I like the term slurp.  Larry likes it, too, IIRC.  You should
alias read_file() to slurp() and export it.  spew()'s not a bad name
either for write_file().

I think the IO::File namespace isn't the place for this module.  IO::File 
has been constant folded to be just File::* for convenience.  Also, the 
IO::* namespace kinda implies its going to be IO::Handle derived or at
least give you some sort of filehandle to work with.  Its not the first
place I'd look for a convenience module to read/write files.

I also don't think its that horrid that it exports a handful of functions.  
There's only five and the reason you load the module is to get those 
functions.

I don't like File::Atomic.  Folks are going to look for the module that
gives you single functions to read and write to a file.  Whether or not
its atomic is largely secondary.


PS  Looking at the docs... the bit about

        my $lines_ref = read_file( $bin_file, array_ref => 1 ) ;
        my $lines_ref = [ read_file( $bin_file ) ] ;

being equivalent is not really true since the latter will copy the whole
array and use more memory, no?

PPS The blk_size argument to read_file() is undocumented and appears to
be unused.

PPPS If its not too late, buf_ref should probably be junked.  You can
get the same effect with scalar_ref.  And while its cute that you can
do this:

        my $text_ref = read_file( $bin_file, buf_ref => \$buffer,
                                             array_ref => 1 ) ;

its not terribly useful.  I also don't think its terribly interesting to
Perl programmers to be orthoginal with read().

PPPPS In the overwrite_file docs, s/typeglob//.  The user doesn't need to
know how you aliased it.


-- 
Michael G Schwern        schwern@pobox.com  http://www.pobox.com/~schwern/
You're more radiant than a memory of breathtaking ecstasy.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About