Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by vsespb (Hermit)
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.


Comment on Re^3: Wrong idioms (open $fh, '<', undef)
Download Code
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 wandering the Monastery: (12)
As of 2015-07-29 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls