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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I like your idea. It's well suited for the example situation. But...
It doesn't scale.
If you have a long list of fields to test, maybe an unknown number of fields, it makes sence to stop checking in the moment you find a mismatch.

This sub (that I use in a project) is both generic and scales well. It's not as Perlish beautiful as some examples, but it's quick. As you will see, it's part of a module.

######################################################## # Return true if all parameters are either defined or # undefined. Return false if there is a mix. ######################################################## sub defined_all_or_none { #my $self=shift; # This is a module, remember? shift; @_||(return 1); if(defined($_[0])) { for(@_) { unless(defined) { return 0; } } } else { for(@_) { if(defined) { return 0; } } } 1; }

Update:
Seeing it on the screen made me see clearer. :-)
The statement:

my $self=shift; # This is a module, remember?
should be reduced to:
shift;
since $self is redundant. Sorry about that.

f--k the world!!!!
/dev/world has reached maximal mount count, check forced.

Edit Masem 2001-07-13 - Code Tags


In reply to Re: Re: Nicer If... by Biker
in thread Nicer If... by SilverB1rd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found