http://www.perlmonks.org?node_id=1026209


in reply to Re: Wrong idioms
in thread Wrong idioms

the problem with that is undef opens a temporary file

:) its http://search.cpan.org/perldoc/Dancer::FileUtils#read_file_content

sub open_file { my ( $mode, $filename ) = @_; open my $fh, $mode, $filename or raise core_fileutils => "$! while opening '$filename' using m +ode '$mode'"; return set_file_mode($fh); } sub read_file_content { my $file = shift or return; my $fh = open_file( '<', $file ); return wantarray ? read_glob_content($fh) : scalar read_glob_content($fh); }

Replies are listed 'Best First'.
Re^3: Wrong idioms (open $fh, '<', undef)
by BrowserUk (Patriarch) on Mar 30, 2013 at 01:57 UTC
    the problem with that is undef opens a temporary file

    And what is to say that is not both a useful feature and exactly what the user intends?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      And what is to say that is not both a useful feature and exactly what the user intends?

      Hmm, open a file for reading, not append, can't read from it, can't write to it -- makes perfect sense, very useful

        Hmm, open a file for reading, not append, can't read from it, can't write to it -- makes perfect sense, very useful

        If it is a non-useful behaviour, then it is open that is at fault and should be fixed.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Wrong idioms (open $fh, '<', undef)
by vsespb (Chaplain) on Mar 30, 2013 at 00:38 UTC
    This will also "open" file without error, if it's not a file, but a directory. Also, does this have any sense?
    return wantarray ? read_glob_content($fh) : scalar read_glob_content($fh);
    In case we don't want an array, it will be converted to 'scalar' anyway.
      What are you talking about?
        I mean open does not detect error if you "open" a directory. Also last code with "wantarray" and "scalar" looks useless.