Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://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":



  • 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 contemplating the Monastery: (4)
As of 2024-04-20 03:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found