Everything depends entirely on the specific context. That's the beauty of TMTOWTDI.

I usually try to sound as English-like as possible, and keep in mind what I'm trying to emphasize: the test or the action? There's no One Right Way, even within the same program or even the same block of code. Go with what makes the most sense for the specific piece of code.

Also, consider the surrounding code. Something as simple as conditionally printing a phone number can depend greatly on why it's doing it. The "standard" way might be:

if ( $obj->show_phone ) { $obj->print_phone_number; }
Here's some code where that probably is best:
# Validate the phone according to basic U.S. rules if ( $phone =~ s/^(1-)?(\d\d\d-?\d\d\d-?\d\d\d\d)$/ ) { $phone = $2; $phone =~ s/-//g; # Strip dashes $obj->set_phone( $2 ); } else { $obj->error( "Invalid phone number" ); } if ( $obj->show_phone ) { $obj->print_phone_number; }
We check the phone number, and make sure it's a valid format, and then when we're done, we might print the phone number. Whether we print or not is incidental to the rest of the block.

But consider this instance where the context is entirely different.

$obj->print_name; $obj->print_address; $obj->print_phone_number if $self->showphone; $obj->print_email_address;

Here, it's more appropriate to show that we're printing a bunch of information, and the phone number is optional. Writing it the "old way", with the phone number block taking three lines, would break up the visual flow, like so:

$obj->print_name; $obj->print_address; if ( $obj->show_phone ) { $self->print_phone_number; } $obj->print_email_address;
Blech.

I think rule two of Perl, after TMTOWTDI, should be "It all depends."

xoxo,
Andy
--
<megaphone> Throw down the gun and tiara and come out of the float! </megaphone>


In reply to Re: Conditional style (if, &&) query by petdance
in thread Conditional style (if, &&) query by traveler

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.