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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

There were no hidden intentions. My question was simply the product of my poor knowledge of Perl :^)

Although it's true that shorter doesn't always mean more efficient, it's also true that when you start with a language you tend to use long and complicated expressions to accomplish tasks that, once you have a little (or no so little) more knowledge, you realize that could have been done in a much shorter (and usually clearer) way.

I was just wondering if this was the case, so the expression:

$var eq 'foo' || $var eq 'bar'

could be translated to something like:

$var eq (foo|bar) (which, of course, does not work)

or similar, the same way the defined-or operator helps to turn $x = $x // 5 into $x //= 5, for instance.

(I understand that the implications of doing $var eq (foo|bar) would probably be more complex).

Consider also that the case I proposed had only two options to compare, so the first version is OK, but with more options a shorter manner would be appreciated. Since that seems not possible, a function would be the best solution as suggested by MidLifeXis.


In reply to Re^2: var comparison by nemesisgus
in thread var comparison by nemesisgus

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (3)
    As of 2014-09-24 03:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (245 votes), past polls