Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

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

Hello, fellow monks,

I've got a silly question regarding the use of short-circuit operators in assignments. I want to do something like this (in my code there's actually and instead of or but I'd like to change it):

if (my $num = $recFono->field_as_text('102') or my $type = $recFono->f +ield_as_text('104')) { something(); }

The problem is of course that the second assignment isn't executed if the first one succeeds. I'd like both assignments to be executed and only then evaluated so the code in the conditional runs if either one or both of those variables are set. A non-short-circuiting or, so to speak.

I've been looking into using the comma operator for the assignments then re-evaluating the assigned variables with or all in one long chain, but apparently those variables aren't in scope yet at that point.

Is what I'm doing here silly or am I overlooking a simple logical trick? Is it a bad idea to execute, assign and do logical evaluation in one go?


In reply to logical non-short-circuit operators by december

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-05-28 06:35 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (98 votes). Check out past polls.