Passing the syntactic if conditional as an argument to print certainly would help with compacting the code and avoiding precedence. For a moment I wasn't sure what would happen if once evaluating to true a zero length string was returned, but of course in a list context it would be discarded as a value.

The initial translation was a straight forward syntactic representation of the if condition. This meditation is aimed at the learning rather than the learned. And as you will see very quickly after this presentation of syntax I do replace the print romeo statement prior to the if conditional. Though you did manage shave off a few more keystrokes

In this meditation interpolation is a factor, as the code is being executed on the command line through the use of the perl command and -e flag. So using the q() operator certainly helps with syntax errors on the command line due to numerous single quotes.

Just like to add here a couple more useful switches for perl commands.

perl -we 'code'. Initiates warnings, but continues to run the code if it can

Shell$ perl -we 'my $word = q(yey);print qq($sword\n);' prints to tty: Name "main::sword" used only once: possible typo at -e line 1. Use of uninitialized value $sword in Concatenation (.) or String at -e + line 1. Shell$ _

perl -ce compiles the code without attempting to execute and returns compilation errors.

Shell$ perl -ce 'my $word = q(yey)); print qq($word\n);' prints to tty: syntax error at -e line 1, near "q(yey))" -e had compilation errors $Shell _

Both very useful debugging switches. Pointing out different possible errors. Use along with 'use strict;' which can also be typed as first statement in a one liner on the command line. When combined, you have a fairly robust debugging practice. On the other hand, not knowing your Hamlet from your Romeo & Juliet is just plain unforgivable.

Coyote


In reply to Re^2: defined ? to be : not by Don Coyote
in thread defined ? to be : not by Don Coyote

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.