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

i have tried ur links and put some debug but it seem the second if doesnt encounter. only n times display of "into the second loop .." please fine the full code

#! C:/perl/bin/perl.exe use strict; use warnings; use File::Copy; use File::Basename; use Cwd; use Data::Dumper; use File::Copy::Recursive qw(dircopy) ; my $fullpath = cwd(); my $value = 0; my $file = basename($fullpath); my $dir = dirname($fullpath); print("$fullpath, $file, $dir"); opendir(my $pathindex, $dir ) or die "Couldn't read index : $!\n"; while (my $currentfile = readdir($pathindex)) { print "\nCurrent Directory File $value\t"; print "$currentfile","\n"; $value++; } print "\nENTER THE PROJECT NAME FROM ABOVE LIST\n"; my $projectdir = <STDIN>; chop($projectdir); my $projectdirpath = "/"."$projectdir"; my $workingdirectory = ($dir.$projectdirpath); chdir($workingdirectory."/trunk"); my $newpath = cwd(); my $source_dirrtl; my $target_dirrtl ; # = ("$newpath"."/rtl2"); opendir(my $index, $newpath ) or die "Couldn't read index : $!\n"; while (my $file = readdir($index)) { if ($file eq "rtl" ) { if(chdir($newpath."/rtl")) { my $currentworkingdir = cwd(); $source_dirrtl = $currentworkingdir; $target_dirrtl = ("$newpath"."/rtl2"); } last; } elsif ($file eq "vhdl") { if(chdir($newpath."/vhdl")) { my $currentworkingdir = cwd(); $source_dirrtl = $currentworkingdir; $target_dirrtl = ("$newpath"."/vhdl2"); } last; } } closedir($index); my $configdirc = $newpath."/configdir"; chdir($configdirc); opendir( my $indexconfig,$configdirc ) or die "Couldn't enter config d +irectory: $!\n"; print("\nCONFIGURATION FILES IN THE CONFIG DIRECTORY \n"); my @rtlfilelist = glob "*.icfg"; print ("\n@rtlfilelist \n"); closedir($indexconfig); my $cChipId; my $cSubVersId; my %data_ids; my $readline; my $toplevelentity; my $ivariant_name; print "\nENTER THE CONFIGURATION FILE NAME FROM THE ABOVE LIST \n"; my $configfile = <STDIN>; open (my $CFILE,$configfile ) || die "couldnt open file: $!"; while ($readline = <$CFILE>) { chomp $readline; my ($key , $value) = (split /::/, $readline); $data_ids{$key} = $value if $key; next if $readline =~ /^ $/; } close($CFILE); for my $key (keys %data_ids) { $cChipId = $data_ids{'chipid'}; $cSubVersId = $data_ids{'subversid'}; $toplevelentity = $data_ids{'Top_level_entity'}; $ivariant_name = $data_ids{'Variant_Name'}; } my $source_dirsim = ("$newpath"."/sim"); my $target_dirsim1 = ("$newpath"."/sim2"); my $source_dirsynth; my $target_dirsynth1 ; opendir(my $indexs, $newpath ) or die "Couldn't read indexs : $!\n"; while (my $file = readdir($indexs)) { if ($file eq "par" ) { if(chdir($newpath."/par")) { my $currentworkingdir = cwd(); $source_dirsynth = $currentworkingdir; $target_dirsynth1 = ("$newpath"."/par2"); } last; } elsif ($file eq "synth") { if(chdir($newpath."/synth")) { my $currentworkingdir = cwd(); $source_dirsynth = $currentworkingdir; $target_dirsynth1 = ("$newpath"."/synth2"); } last; } } closedir($indexs); mkdir($target_dirrtl,0777); mkdir($target_dirsim1,0777); mkdir($target_dirsynth1,0777); my $filertl = dircopy($source_dirrtl, $target_dirrtl); my $filesim = dircopy($source_dirsim, $target_dirsim1); my $filesynth = dircopy($source_dirsynth, $target_dirsynth1); opendir $source_dirsynth: $!"; chdir("$target_dirrtl"); my $m4file = "$projectdir".".m4"; open(MYFILE,">>$m4file"); print MYFILE ("define(`m4_cChipId',`16#$cChipId#,16')\n"); print MYFILE ("define(`m4_cSubVersId',`16#$cSubVersId#,16')\n"); print MYFILE ("define(`m4_$projectdir',`1')\n"); print MYFILE ("define(`m4_$ivariant_name',`1')\n"); print MYFILE ("define(`m4_rtl',`rtl2')\n"); if(my $output1 = `test.bat`){ print("\n succesfully executed\n"); } chdir("$target_dirsynth1"); ###################################################################### +############################################## #added on 13/5/2016 opendir( my $synthdir,$target_dirsynth1) or die "Couldn't enter config + directory: $!\n"; print("\nSYNTHESIS INPUT FILES IN CURRENT DIRECTORY \n"); my $synthfilelist = glob "*.qsf"; print ("\n$synthfilelist \n"); #closedir($target_dirsynth1); my $originalquartus ; my $latestquartus ; my $readlineqo; my $readlineql ; #print "\nENTER THE CONFIGURATION FILE NAME FROM THE ABOVE LIST \n"; #my $configfile = <STDIN>; open (my $OFILE,$synthfilelist) || die "couldnt open file: $!"; while ($readlineqo = <$OFILE>) { chomp $readlineqo; if ($readlineqo =~ /ORIGINAL_QUARTUS_VERSION/) { my @originalqarray = (split / +/ , $readlineqo); $originalquartus = $originalqarray[3]; print "\nthe original quartus $originalquartus\n"; } #next if $readlineqo =~ /^ $/; # } # close($OFILE); #open (my $LFILE,$synthfilelist) || die "couldnt open file: $!"; # while ($readlineql = <$LFILE>) { # chomp $readlineql; print "into the second loop $readlineqo\n"; if ($readlineqo =~ /LAST_QUARTUS_VERSION/) { my @latestqarray = (split / +/ , $readlineqo); $latestquartus = $latestqarray[3]; print "\nthe latest quartus $latestquartus\n"; } next if $readlineqo =~ /^ $/; } close($OFILE); closedir($target_dirsynth1); ###################################################################### +############################################## print("\n Enter y or n to continue with synthesis \n"); my $choice = <STDIN>; chop($choice); if ($choice eq "y") { system ("qcmd.bat $toplevelentity"); } else { print "continue manually with synthesis\n"; }
block that is causing problem is inside #line with date of today. the whole code is running and even the last print statement also comes but after n times print of "into the second loop..".

Replies are listed 'Best First'.
Re^5: searching two pattern sequentially from one file
by Corion (Patriarch) on May 13, 2016 at 11:44 UTC

    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.

      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.

Re^5: searching two pattern sequentially from one file
by haukex (Archbishop) on May 13, 2016 at 11:52 UTC

    Hi mrityunjaynath,

    Due to lack of time I have only briefly skimmed your code - and I think that many other readers would also appreciate it if you could reduce the amount of code needed to reproduce the problem, as the pages I linked to earlier explain. At first glance, it seems that the block of code inside the ##### comment markers is mostly independent of the rest of the code.

    Does your script ever output "into the second loop set_global_assignment -name LAST_QUARTUS_VERSION 11.1"?

    If not, then my guess is that you have more than one file with the extension .qsf in the path $target_dirsynth1 and the glob is picking the wrong one.

    Regards,
    -- Hauke D