Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: if condition within module

by kcott (Archbishop)
on Aug 16, 2017 at 07:24 UTC ( [id://1197491]=note: print w/replies, xml ) Need Help??


in reply to if condition within module

G'day gowthamvels,

I want to use a if conndtion like below ...

if ($col6 =~ /^\Q97517\E/ } elsif $col6 =~ /^\Q97516\E/))

The very first thing you should do is read "Perl introduction for beginners" because, from what you've demonstrated, you do not, at present, have a basic understanding of Perl code syntax.

if can be used in a compound statement. The construct looks like this:

if (CONDITION) { ACTION_WHEN_CONDITION_IS_TRUE }

That may be followed by zero or more alternative conditions and actions:

elsif (ALTERNATIVE_CONDITION) { ACTION_WHEN_ALTERNATIVE_CONDITION_IS_TRUE }

Finally, all of that may be optionally terminated with:

else { ACTION_WHEN_CONDITION_IS_FALSE }

This is documented in "perlsyn: Compound Statements".

if may also be used as a statement modifier:

ACTION_WHEN_CONDITION_IS_TRUE if CONDITION;

This is documented in "perlsyn: Statement Modifiers".

There is also an "if pragma". This does not appear to have anything to do with what you're currently attempting; however, be aware of it to avoid confusion in other (unrelated) code, discussions or documentation.

Perl has no builtin if() function. I mention this because "if()" has been used in a number posts in this thread (including by yourself: "I am asking for how to use the if() in this code") and that usage could be confusing to a Perl novice.

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-24 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found