Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: RFC: New style for argument check in subs

by LanX (Saint)
on Sep 05, 2012 at 11:41 UTC ( [id://991817]=note: print w/replies, xml ) Need Help??


in reply to Re: RFC: New style for argument check in subs
in thread RFC: New style for argument check in subs

As I already said, accepting undef as valid argument is such a special and rare case that it should be covered by another approach. (see footnotes in OP)

Here using ternaries is far more explicit and shows that a special argument undef is accepted.

my $a = exists $arg{a} ? $arg{a} : 'else case';

But I agree that it's better to name the error die('Undefined argument!') instead of 'Missing argument' to avoid such misunderstandings.

Cheers Rolf

Replies are listed 'Best First'.
Re^3: RFC: New style for argument check in subs
by Tux (Canon) on Sep 05, 2012 at 15:05 UTC

    Not rare at all! Both as unnamed and as named parameter used in DBI + DBD::CSV:

    use DBI; my $dbh = DBI->connect ( "dbi:CSV", # Unnamed, driver undef, # Unnamed, username undef, # Unnamed, password { f_ext => ".csv/r", # Named and defined f_schema => undef, # Named and undefined });

    FWIW all NULL values in a database are refered to through undef, so you'll see a lot of those in both named and unnamed arguments to functions and methods.


    Enjoy, Have FUN! H.Merijn
      Good point.

      But in those cases checks for existence should be explicit.

      UPDATE: You convinced me that

      *** Unpack Named First

      is a danegrous option. Thanks :)

      Cheers Rolf

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2024-04-19 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found