Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Dynamic if statement

by ideasuntouched (Initiate)
on Mar 25, 2010 at 07:13 UTC ( [id://830760]=perlquestion: print w/replies, xml ) Need Help??

ideasuntouched has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Dynamic if loop
by CountZero (Bishop) on Mar 25, 2010 at 07:23 UTC
    What have you tried?

    What do you mean by an if-loop?

    Perl has for or foreach-loops, while and until loops. They can be further modified with next, last, redo and continue operators.

    There are a number of hidden loop constructs such as map and grep.

    Finally you can "roll your own" with labels, if ... then ... else and goto

    Plenty of choice: it is the embarrassment of riches.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Maybe if-loop is the new name for the FOR-CASE paradigm. :)

      -- Randal L. Schwartz, Perl hacker

      The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Re: Dynamic if loop
by moritz (Cardinal) on Mar 25, 2010 at 07:24 UTC
    if can conditionally execute statements, but it can't loop. Maybe you meant while? (see perlintro, perlsyn).

    Your question seems very generic, but makes very little sense at the same time - please try to give us a much more concrete idea of what you want to do, and what your problem is.

Re: Dynamic if loop
by ikegami (Patriarch) on Mar 25, 2010 at 07:28 UTC

    ok. What is it suppose to do?

    Note that if isn't a form of loop. It does not execute code repeatedly. It causes blocks of codes to be executed conditionally.

      hi, I have a method whose output is n-number of words using those words i need to check a matching condition against another set of words.so i need to generate if statements for matching the conditions based on the number of words that comes as output from the method.i hope it is clear. thanks...

        Eek, you really did mean code generation. Code generation is not the answer. Why would you build code to check conditions instead of just checking conditions.

        You're actual question appears to be "How do I check a set of words (returned by a function) against a set of words?"

        Check for what? Are you trying to find the intersection of the sets?

        How does the function return the set of words? As a list of strings?

        yes if executes conditionally i want to execute the same if statement for different conditional word against different input word.. it may look as below.. foreach $ruleword(@splitrule) { if($word=~m/$ruleword/igs) { print "\t$word\tmatched\n"; } }
Re: Dynamic if statement
by CountZero (Bishop) on Mar 25, 2010 at 16:04 UTC
    You have edited your original posting, which now makes all nodes which answered your original query look totally weird. Please do not do that: it is considered bad form in the Monastery.

    Rather either keep the original posting and provide additional information in follow-up nodes or update it but clearly indicate what was changed (hint: use <ins> ...</ins> for insertions and <del> ...</del> for deletions.

    If we understand your new question, you need to check a list of words against another list of words. If you like to avoid two loops and repeated regex-tests, have a look at Regexp::Keywords (A regexp builder to test against keywords lists), Regexp::Match::List (Matches a string to a list of regular expressions) or Regexp::Assemble (Assemble multiple Regular Expressions into a single RE).

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

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

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

    No recent polls found