Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by vsespb (Hermit)
on Apr 02, 2013 at 09:47 UTC ( #1026641=note: print w/ replies, xml ) Need Help??


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

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?


Comment on Re^7: Wrong idioms (open $fh, '<', undef)
Select or Download Code
Re^8: Wrong idioms (open $fh, '<', undef)
by Anonymous Monk on Apr 02, 2013 at 12:12 UTC

    You must be running Windows? or? Cygwin?

    Yeah :)

    for wantarray: ... what's the point in using 'wantarray' in uni_func here?

    clarity of intent, explicitness

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2014-08-29 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls