Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Wrong idioms (open $fh, '<', undef)

by vsespb (Chaplain)
on Mar 30, 2013 at 00:38 UTC ( #1026213=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026213]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2016-09-25 01:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (463 votes). Check out past polls.