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


In reply to Re: if condition within module by kcott
in thread if condition within module by gowthamvels

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.