in reply to Re^4: searching two pattern sequentially from one file
in thread searching two pattern sequentially from one file

Not very much of that code is necessary. Your later code doesn't need all that readdir stuff and the stuff reading the config file.

Note that you are printing out the current line in the line:

print "into the second loop $readlineqo\n";

So, if you are seeing the output into the second loop .., then your line consists of two dots. Maybe that is the case, but maybe you are reading the wrong file.

Replies are listed 'Best First'.
Re^6: searching two pattern sequentially from one file
by mrityunjaynath (Acolyte) on May 16, 2016 at 08:46 UTC

    this code is doing many things. at first it is generating rtl file using m4 switch and values of some generic variable from config file and then its synthesizing them. what i wanted is to provide a switch for one particular version of synthesizing software and that to as per the qsf file (for which i added the portion of code that would get value about last and original quartus version.). to do so i have coded the portion inside two ###################### blocks. though the code is working it is only able to get original quartus version and not the last quartus version inspite it is printing "into the second loop $readlineqo" for that no of times as there are lines in qsf file. couldnt debug what mistake i am doing .

      this code is doing many things ... couldnt debug what mistake i am doing

      These two statements are not unrelated. There are various aspects of your code as it stands which will hinder debugging. The main one is that it is monolithic - if you were to split out the various parts into subs it would help to isolate problems and allow for simpler testing.

      Other potential pitfalls include:

      • Inconsistent indenting. perltidy is an obvious tool to help with that.
      • Lack of fault tolerance. eg. calling chdir without checking to see whether or not it has succeeded. Consider autodie as a first-order fix.
      • Lack of meaningful comments. Some lines of code commented out with no explanation as to why.
      • Variables assigned to which are never read (eg. $filesynth). perlcritic can pick up such situations.

      Writing quality code isn't easy but having put the effort in (even just using the tools I've mentioned) it does make debugging, testing and maintenance so much easier.

      Good luck with your ongoing debugging.

      If your code is printing

      into the second loop $readlineqo\n

      instead of printing the line it has read, then you have single quotes instead of double quotes. Make sure your code reads:

      print "into the second loop $readlineqo\n";

      (with the double quotes).

      Please reduce your program to a program that still exhibits the problem but is only about 20 lines long, and also show us a short (like 10 lines) example of the problematic input. Using these two parts, we can likely reproduce the problem and diagnose much better where the problem lies.

      Usually while reducing your program to a short program that still exhibits the problem, you will find the source yourself. In the event that you don't find the problem yourself, we are here to help you, but you need to help us help you better first by reducing the program to a small size and provide the problematic input data.