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

comment on

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

Not sure what you mean by "quick". Do you want an equally succint, but more "English" way of expressing conditions? Or do you want to type even fewer characters than the expressions you have already provided?

If "even shorter" is your goal, then I'm afraid you would lose clarity. Though some golf expert is sure to point the way to "even shorter", I wouldn't use that in production code.

If "just as short but more English" is the goal, then I would say, your question is a little like asking "Is there a fast way to say 'Je ne sais pas' in French, without actually saying 'Je ne sais pas'?" Every language, even a programming language, has its idiom. The expressions you have written are the idiom of Perl, as much as 'Je ne sais pas' is the idiom of French.

Best of luck and welcome to Perl Monks (and Perl), beth

Update:Citromatik saw an angle to your question that I missed. In the spirit of Citromatik's answer below, a pre-Perl 5.10 equivalent is if ($string =~ /^(?:A|B)$/). if ($string =~ /^(?:A|B)\z/).To compare $string to the strings A,B,C,D you can do $string =~ /^(?:A|B|C|D)$/ $string =~ /^(?:A|B|C|D)\z/ and so forth. But I think the syntax that you have chosen in your post is much more readable unless you have a long list of strings to which you want to compare $string

Update: as per Kyle.


In reply to Re: conditional syntax options by ELISHEVA
in thread conditional syntax options by Anonymous Monk

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 sharing their wisdom with the Monastery: (6)
As of 2024-04-19 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found