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


in reply to Re^2: Wrong idioms (open $fh, '<', undef)
in thread Wrong idioms

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.

Replies are listed 'Best First'.
Re^4: Wrong idioms (open $fh, '<', undef)
by Anonymous Monk on Mar 30, 2013 at 02:40 UTC
    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.

        I mean open does not detect error if you "open" a directory.

        Sure it does

        $ perl -e " open $dirname, q/../ or die $!, $/, $^E, $/ " Permission denied Access is denied $ perl -e " open $dirname, q/../ or die join qq/\n/, $!,$^E,grep( { $! +{$_} } keys %! ) " Permission denied Access is denied ERROR_INVALID_DATA EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X EMR_SETBRUSHORGEX EVENT_SYSTEM_CONTEXTHELPEND EACCES at -e line 1.

        Also last code with "wantarray" and "scalar" looks useless.

        No, its is not useless. You must not know perl well.