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

Re: new slurp module

Thread Previous | Thread Next
October 24, 2003 08:52
Re: new slurp module
Message ID:
On Fri, Oct 24, 2003 at 10:53:43AM -0400, Alex J. Avriette wrote:
> On Thu, Oct 23, 2003 at 11:49:50PM +0200, Abigail wrote:
> > If that's an argument to put modules doing rather trivial things
> > into the core distribution, why stop at File::Slurp? Why not just
> > include the whole of CPAN?
> Abigail, there is no reason to be contrary about this.
> > The core distribution is already bloated beyond belief, and IMO,
> > File::Slurp has not much to offer. It's replacing idioms of 1, 2
> > or 3 lines with 2 line idioms.
> Or, one-line idioms. For example,
> my @stuff = map { something() } read_file( "filename" );

That's a two line idiom (you need the 'use File::Slurp;' as well),
replacing a one liner:

  my @stuff = map {something ()} do {local @ARGV = "filename"; <>};

> removes several steps. I personally find it irritating to find
> all these errant filehandles all over the place, which are used to
> do one thing -- read a file. Additionally, users feel the need to
> make half-thought-out for loops for simply reading through a file.
> If we can encourage users to use something as clear and as facile as
> the File::Slurp methods, it would make my job easier, and keep many
> of the users of the module happier. I can't tell you how many times
> I've distributed this module as a part of my application because it
> wasn't in Core. In fact, I pushed to have it included in the OpenBSD
> core for the adduser program.

I bet there are lots of people whose job would be easier if all of
CPAN was included in the core distribution. Many programs will have
a dependency on one or more external modules. If we add File::Slurp
to the distribution, we should also add String::ChopChop which replaces
the two-line idiom

    $str =~ s/^\s+//;
    $str =~ s/\s+$//;

with the two-liner:

    use String::ChopChop;
    chopchop ($str);

After all, it's a common operation, but often done in ugly or inefficient
ways. <Python>Time we show the world the true way of doing this.</Pyton>

> The read_file and write_file idioms would be very valuable in helping
> make some of the code generated by newer programmers cleaner (e.g., 
> one-line calls instead of 10-line loops), and also by helping the
> more advanced programmers use some of the more advanced techniques
> (such as the map, above). At present, neither is easy.

chopchop would also be very valuable in helping make some of the code
generated by newer programmers cleaner. It won't help the more advanced
programmers, but then, neither will File::Slurp.

> > Mention File::Slurp in the FAQ, I'd say.
> I fail to see what this would accomplish.

You mean, people don't read the FAQ?

>                                           Many sites are loathe to
> include modules with their application, or to go out and get modules
> from CPAN (notably, because they all seem to think CPAN will upgrade
> their perl).

On the other hand, there are many sites that are still using 5.6.0,
or even older versions. You can use File::Slurp from CPAN *right now,
with your current perl*. If you include File::Slurp into the core
distribution, you have to wait till 5.10, and then have to convince
"many sites" to upgrade their perl. 

OTOH, if you deploy your applications in a self contained manner (that
is, including a perl with the appropriate configure options, and of the
appropriate version), including File::Slurp in your deployed application
is a snap.

>              If, as you say, the core is already bloated beyond belief,
> then, indeed, what is the problem with "one more module." Find something
> you find of less utility or merit, and suggest it be taken OUT.

The fact that the distro is already bloated is no reason to just open
the floodgates for trivial stuff.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About