On 06/29/2016 01:17 PM, Eric de Hont wrote:
Op 29-06-16 om 18:20 schreef Uri Guttman:
On 06/29/2016 06:03 AM, Eric de Hont wrote:


sub slurp_file {
    my $file = shift;
    local $/;
    open my $fh, '<', $file or die "Can't open $_: $!\n";

$_ is not set anywhere. you likely meant to use $file
O, dear. Just a bit too quick and dirty...
since you are correct about modules being already there, why do you write your own versions of slurp_file and write_file? the module File::Slurp has those functions which are stable, fast and debugged.

Good point. I decided just to show the OP how to do it in a better way than his `cat`.

There are issues concerning File::Slurp it seems, which I did not want to drag into this topic.

For the issues in question see: http://blogs.perl.org/users/leon_timmermans/2015/08/fileslurp-is-broken-and-wrong.html


file::slurp has over 600 reverse dependencies on cpan and is used in many perl shops. i would call that pretty stable and useful.

thanx,

uri

Reply via email to