in reply to Re: Dynamic if loop
in thread Dynamic if statement

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...

Replies are listed 'Best First'.
Re^3: Dynamic if loop
by ikegami (Patriarch) on Mar 25, 2010 at 07:53 UTC

    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?

      Well code generation might be an answer. If you need to build the condition once and evaluate many times. Which doesn't really seem to be the condition in this case, but sometimes it's good to do all the work you can upfront, outside the loop and then just call the generated and eval""ed function within the loop.

      Not the easiest thing to write and debug, but sometimes the best solution performance-wise.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Re^3: Dynamic if loop
by ideasuntouched (Initiate) on Mar 25, 2010 at 07:41 UTC
    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"; } }

      When your code snippet is wrapped in <code> ... </code> tags, it looks like this:

      foreach $ruleword ( @splitrule ) { if( $word =~ m/$ruleword/igs ) { print "\t$word\tmatched\n"; } }

      And that looks fine (except the /g is probably not useful in this context). So why do you think you need to generate code?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.