Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by Anonymous Monk
on Mar 30, 2013 at 02:40 UTC ( #1026227=note: print w/replies, xml ) Need Help??


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

What are you talking about?
  • Comment on Re^4: Wrong idioms (open $fh, '<', undef)

Replies are listed 'Best First'.
Re^5: Wrong idioms (open $fh, '<', undef)
by vsespb (Chaplain) on Mar 30, 2013 at 09:04 UTC
    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.

        perl -e " open $dirname, q/../ or die $!, $/, $^E, $/ "

        You must be running Windows? or? Cygwin?

        Under linux:

        perl -e " open $dirname, q/../ or die $!, $/, $^E, $/ " bash: !,: event not found
        perl -e ' open $dirname, q/../ or die $!, $/, $^E, $/ ' (no error)

        for wantarray:

        use strict; use warnings; sub array_func { my ($arg) = @_; if (wantarray) { return map { $arg } 1..3; } else { return map { $arg*2 } 1..5; } } sub uni_func { my ($arg) = @_; return wantarray ? array_func($arg) : scalar array_func($arg); } sub small_func { my ($arg) = @_; return array_func($arg) ; } print join(';', uni_func(7)); print "\n"; print scalar(uni_func(7)); print "\n"; print join(';', small_func(7)); print "\n"; print scalar(small_func(7)); print "\n"; print join(';', array_func(7)); print "\n"; print scalar array_func(7); print "\n"; __END__ prints: 7;7;7 5 7;7;7 5 7;7;7 5
        what's the point in using 'wantarray' in uni_func here?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026227]
help
Chatterbox?
[Discipulus]: oh and dont miss my last poetry!
[marioroy]: Hello all. After several attempts, am able to move forward and will soon release a Parallel:: ForkManager compatible MCE::Hobo:: Manager, also MCE::Hobo::Simple, and refactored MCE::Hobo engine supporting multiple instances. Wait works beautifully.
[marioroy]: MCE::Shared has been refined that it allows sharing Tie::File and hash objects containing {fh} key.
[marioroy]: It's taken so long to take Hobo to a new level. Threads-like and Parallel:: ForkManager management capaiblities.
[marioroy]: This will complete the 4 years in the making and likely time to move on to something els.
[marioroy]: s/els/else.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2017-05-26 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?