Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^3: Options with optional values and condititions

by runrig (Abbot)
on Oct 02, 2012 at 18:50 UTC ( #996894=note: print w/replies, xml ) Need Help??

in reply to Re^2: Options with optional values and condititions
in thread Options with optional values and condititions

if ($foo) probably-unintentionally checks for truth...
It was intentional by me, though I don't know what the OP wants. From the docs:
Using a colon ":" instead of the equals sign indicates that the option value is optional. In this case, if no suitable value is supplied, string valued options get an empty string '' assigned, while numeric options are set to 0.

So yes, if you supply a value of "0" to a string option, you'll miss it. If you want to catch that situation you'll have to code for it. I often assume such strings are invalid in most practical situations.

  • Comment on Re^3: Options with optional values and condititions

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996894]
[1nickt]: thezip use Path::Tiny. @paths = path("/foo")-> children; (Excludes "." and ".." automatically.)
[1nickt]: (Also takes a compiled regexp as an arg to filter the list)
[1nickt]: For multiple dirs use iterator(): $it = path("/foo")-> iterator; while ( my $path = $it->() ) {...}
[1nickt]: (also skips . and .. automatically, and follows subdirs if you set <c\>recurse => 1</c>
[1nickt]: $it = path("/foo")-> iterator(recurse => 1 );

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2017-03-28 18:45 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (339 votes). Check out past polls.