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

Hi mrityunjaynath,

When I run your code against this sample input, I get the output "the original quartus 9.1" and "the latest quartus 11.1" - so it would seem that the problem is happening elsewhere in your code.

To narrow down where the problem is occurring, sometimes the simplest thing to do is print debug output at strategic places in your code to monitor its progress, see also the Basic debugging checklist. Another option is stepping through your code with the debugger (tutorial).

Once you've narrowed down where your problem is occurring, boil down your code and sample input into a Short, Self Contained, Correct Example, that is, a piece of code that compiles and reproduces the problem, along with its sample input and the expected output vs. actual output including error messages (see also How do I post a question effectively?), and post it here.

Often this process will help you discover the bug and the fix too! :-)

Hope this helps,
-- Hauke D

  • Comment on Re^3: searching two pattern sequentially from one file

Replies are listed 'Best First'.
Re^4: searching two pattern sequentially from one file
by mrityunjaynath (Acolyte) on May 13, 2016 at 11:24 UTC

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

      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 .

      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