Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

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

Thanks!


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

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

    No recent polls found