laziness, impatience, and hubris PerlMonks

### Re^2: Common Perl Pitfalls

by chrestomanci (Priest)
 on Apr 11, 2012 at 12:59 UTC ( #964534=note: print w/replies, xml ) Need Help??

in reply to Re: Common Perl Pitfalls

Rather than mess around with $INPUT_RECORD_SEPARATOR (AKA:$/), and restore it afterwards, a better method would be to use the File::Slurp module.

It is another common Perl pitfall to write new code for a common problem when you should have looked on CPAN. There is a very good chance that you will find a fully debugged implementation that considers all the edge cases. It never ceases to amaze me that people would prefer to spend half a day writing and debugging code, instead of 15 minutes finding and installing a module from CPAN.

Replies are listed 'Best First'.
Re^3: Common Perl Pitfalls
by JavaFan (Canon) on Apr 11, 2012 at 14:23 UTC
It always amazes me people prefer downloading a CPAN module, and using it, over writing a one-liner. I'm even more amazed that people think that just because there's a module on CPAN, it automatically is fully debugged and covers all the edge cases.

I do wonder though, if it takes half a day to write:

my $slurp = do {local$/; <HANDLE>};
[download]
how long do you need to type in:
use Some::Module::From::CPAN;
my $slurp = Some::Module::From::CPAN->some_API(some_argument); [download] Twice the number of lines, so, a full work day? use File::Slurp; my$text = read_file( 'filename' );
[download]

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.

Note.
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).

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>};
[download]
it could easily be.

Create A New User
Node Status?
node history
Node Type: note [id://964534]
help
Chatterbox?
 [Corion]: Option a) would mean launching cmd.exe /k c:\path\to\ batchfile- launching-perl- script.cmd. Option b) would be to add pause as the last line of said batch file. [LanX]: First day after holidays ... and already stressed by the fact that colleagues changed stuff without communication ... apparently I'm the only one trying to fight entropy [Corion]: LanX: The command is always in the history if you typed it in before. If you didn't type the command into the command line, it will not be there. I think there is doskey which can stuff command lines into the history LanX damns the cult of CB ;-) LanX WTF WTF WTF [LanX]: please forget my last 3 posts [LanX]: Yeah option a doesn't go into history [LanX]: probably I need to teach the app to restart after C-c Kill [Corion]: LanX: Maybe have an infinite-loop cmd file? Much easier than trying to manage that from within Perl IMO [Corion]: Alternatively, relaunch the application from cron (or a Windows cron) every minute

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2017-03-27 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should Pluto Get Its Planethood Back?

Results (320 votes). Check out past polls.