<div dir="ltr">Alan, thank you for the insight. I will look into this.<div><br></div><div>Richard</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">El sáb, 6 feb 2021 a las 14:06, Alan Mead (<<a href="mailto:amead2@alanmead.org">amead2@alanmead.org</a>>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
Maybe I'm stating the obvious, but if you don't want to change the
code, then you need to define the branching logic and
questions/answers as data and write an "engine" that processes the
data and decides what question is next based on the current state
(e.g., the answer to the current question, and possibly other
information relevant to your application). You should beware that
this could become icky. For example, it may be possible to create
bugs in the branching logic.<br>
<br>
I don't know what the context is, but I believe what you're
describing is called "skip logic" and "branching" in the survey
industry and it's implemented in packages like LimeSurvey:
<a href="https://www.limesurvey.org/blog/20-blog/129-skip-logic-and-branching-equip-your-survey-structure-with-intelligent-paths" target="_blank">https://www.limesurvey.org/blog/20-blog/129-skip-logic-and-branching-equip-your-survey-structure-with-intelligent-paths</a><br>
<br>
Even if you cannot use Lime Survey, you might look at how they
implement the rules and think about how you would build an engine to
implement this yourself. <b>I think in essence</b>, each question
has an ID and the survey has a sequence. Each item either has skip
logic, or doesn't. If skip logic exists for a question, then each
response to the question needs a ID to branch to. If not, the next
question in the survey sequence is chosen. It wouldn't be a
monumental task to write this kind of simple engine. I guess
implicit in this is that you should be reading your questions and
answers from some kind of human- and machine-readable format like
YAML or JSON. This file is where you would insert the skip logic in
a format you devise. I found references to XPDL in googling as
described below. You should define as much complexity as you need. I
had a student who couldn't use SurveyMonkey because he wanted to
administer a six-item depression survey, score it, and then branch
based on whether the score indicated depression or not. At the time,
scoring survey questions and adding them up was beyond what SM could
do. He found that Qualtrics did have a feature to do this.<br>
<br>
Implicit in my description above is that the main purpose is to
collect and store survey responses. If your goal is more like
reaching a decision (e.g., "Based on your responses, an
adjustable-rate mortgage would best suit your needs...") then the
questions AND the ending decisions have to be part of the data and
perhaps the logic isn't as simple as above (maybe there is no
sequence and every question needs a branch, or there are sections of
questions that go together and branch between sections). It looks
like XPDL is an industry standard (in the workflow industry) for
representing this.<br>
<br>
If you google "decision tree" you get a bunch of hits for machine
learning. I googled "Perl decision process tree" and that lead me to
potentially useful articles like the one below, in which someone
wants to create flexible rules about "workflow" (how how tickets are
routed in a ticketing app):
<a href="https://www.perlmonks.org/?node_id=222257" target="_blank">https://www.perlmonks.org/?node_id=222257</a><br>
<br>
This is also similar to the way web frameworks work. But I think
there you'd be writing code to perform each step, so that's probably
not helpful.<br>
<br>
I am continually amazed by what's on CPAN but I doubt you will find
a module for anything like skip logic/workflow in abstract. I think
it's more likely to be embedded in a context, like the ticketing
app, a survey, or a web frame work. But it looks like there are some
Perl modules for implementing workfows. <br>
<br>
-Alan<br>
<br>
<br>
<div>On 2/6/2021 8:53 AM, Richard Reina
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">I am trying to write code that would guide a user
through a series of questions and depending on their answers
given ask them different questions. I can of course do this with
procedural code but it has occured to me that it might begin to
get messy especially when exceptions mount. For example, if the
answer to the third question is no, then skip to question 8. So
I am looking for a way to structure such code to make it cleaner
and perhaps easier to maintain, Does anyone know of any examples
of similar projects that I can reference?
<div><br>
</div>
<div>Thanks,</div>
<div><br>
</div>
<div>Richard </div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
Chicago-talk mailing list
<a href="mailto:Chicago-talk@pm.org" target="_blank">Chicago-talk@pm.org</a>
<a href="https://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">https://mail.pm.org/mailman/listinfo/chicago-talk</a>
</pre>
</blockquote>
<br>
<pre cols="72">--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
<a href="http://www.alanmead.org" target="_blank">http://www.alanmead.org</a>
The irony of this ... is that the Internet is
both almost-infinitely expandable, while at the
same time constrained within its own pre-defined
box. And if that makes no sense to you, just
reflect on the existence of Facebook. We have
the vastness of the internet and yet billions
of people decided to spend most of them time
within a horribly designed, fake-news emporium
of a website that sucks every possible piece of
personal information out of you so it can sell it
to others. And they see nothing wrong with that.
-- Kieren McCarthy, commenting on why we are not
all using IPv6
</pre>
</div>
_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org" target="_blank">Chicago-talk@pm.org</a><br>
<a href="https://mail.pm.org/mailman/listinfo/chicago-talk" rel="noreferrer" target="_blank">https://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
</blockquote></div>