Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Complex conditional statements

by mrpeabody (Friar)
on Jun 16, 2005 at 17:17 UTC ( [id://467366]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Complex conditional statements
in thread Complex conditional statements

I'm trying to introduce a --test option to the script, that would do a "dry run", without actually transferring the file, just printing status messages on every step. Since the majority of the code is the same for test and normal run, I want to use those if, and, or, unless keywords, and I want to keep the code compact. I have a C background, so my code did look like a C program... well, initially it did. But I'm realy impressed with the power of Perl to mangle several statements together like this, and trying to use that.
Now the problem is clear. You have a simple requirement that can be expressed clearly in code. However, giddy with the newly-discovered expressive power of Perl, you're looking for a way to squeeze what you want to say into as small a space as possible.

Don't. It makes code ugly, complicated, and damned near impossible to understand, never mind maintain. It makes people hate Perl programmers and hate Perl. It's a fun game, and can even teach you something about the language, but you should never do it on production code (defined as code you will run more than once).

In addition to which, the specific trick you're trying to use is not allowed. Statement modifiers are limited to one per statement.

If there are better ways to do this, I'm open to suggestions...
ikegami has the right idea:
if ($comment or $test) { $a = 3; print "--> $a\n"; } else { print "no way!\n"; }
By the way, where can I find references to the syntax of those Perl keywords? I tried to search for them, but they aren't functions, and Google promptly omits them from the search criteria...
They are documented in perlsyn.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-28 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found