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

Re: Flag variables

by TomDLux (Vicar)
on Mar 05, 2003 at 08:57 UTC ( #240558=note: print w/ replies, xml ) Need Help??


in reply to Flag variables

Flag variables are often a warning of using the wrong program structure.

On the other hand, I came across some convulted printing code :

if ( ..A... ) { if ( ..B.. ) { if ( ..C.. ) { if ( ..D.. ) { print ..... } else { print ... } } else { if ( .. D2.. ) { ... you get the idea ...
It took some effort to reverse engineer the original specs, but I was able to simplify it to:

my $flag1 = cond1; my $prefix = (( cond2 ) ? "strting1" : "strring2"; ... print "$prefixA$suffixB" if ( condC );
While things are spread out in the sense that things are detected and saved in flags in one spot, and used later, it avoids dealign with a highly nested conditional ( especially since some possible states were ignored.

Of course, there are other solutions to the problem I encountered, but that's not relevant tothe topic of flag variables.


Comment on Re: Flag variables
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://240558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2015-07-02 04:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (27 votes), past polls