Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^4: Common Perl Pitfalls

by jdporter (Canon)
on Apr 11, 2012 at 15:15 UTC ( #964562=note: print w/replies, xml ) Need Help??

in reply to Re^3: Common Perl Pitfalls
in thread Common Perl Pitfalls

use File::Slurp; my $text = read_file( 'filename' );

Yeah, that's a whole day's work.
I submit that finding the documentation on such a method is substantially easier than finding the documentation (for lack of a better word) for the snippet you gave.

The "cost" of useing the module is amortized over all the calls you make to any of its methods (of which File::Slurp has several useful ones).

And the cost of downloading a module is amortized over all of the times you ever use it (at least on that machine).

Replies are listed 'Best First'.
Re^5: Common Perl Pitfalls
by JavaFan (Canon) on Apr 11, 2012 at 15:29 UTC
    Yeah, that's a whole day's work.
    Maybe not for you or me. But for someone who needs half a day to type
    my $test = do {local $/; <HANDLE>};
    it could easily be.
      half a day to type

      You keep dwelling on that, but I think you're misdirecting. He wrote, "spend half a day writing and debugging code", not "half a day to type in one line".

      If someone has a bug they need to track down, they're far more likely to waste cycles on a line like $_=do{local$/;<>}; than one like $_=read_file($file);

      Now let's compare apples to apples:

      use File::Slurp; my $text = read_file( 'filename' );
      my $text = do { local $/; open my $fh, '<', 'filename' or die "Error opening filename for read - $!"; <$fh> };

      For most programmers, the former looks sane.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964562]
[shmem]: Discipulus reminds me of an irish saying: "I would guess a tomorrow can wait 'til this day is done" :-)
[LanX]: nite! :)
[Discipulus]: or a spanish one: ' qui mucho se despide no quiere despedirse'
shmem slides into the envelope
[shmem]: Discipulus *quien*
[Discipulus]: quien ..
[Discipulus]: me too, i need a Dumas time, see you
[shmem]: que descanses bien, aprendiz
shmem wuff & wech

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-04-29 22:53 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (534 votes). Check out past polls.