Hi mrityunjaynath,
When I create a simple test input file
ORIGINAL_QUARTUS_VERSION a b c d LAST_QUARTUS_VERSION w x y z
Your code works for me (after commenting out the initial opendir, which appears unnecessary), giving the (I assume) expected output "the original quartus c" and "the latest quartus y".
Are you sure your input file contains the string "LAST_QUARTUS_VERSION"? Could you show a sample input file for which your code fails? See Short, Self Contained, Correct Example.
Note that you don't need to open the file twice, you can combine your two loops into one:
my $originalquartus; my $latestquartus; open( my $OFILE, $synthfilelist ) || die "couldnt open file: $!"; while ( my $readlineqo = <$OFILE> ) { chomp $readlineqo; if ( $readlineqo =~ /ORIGINAL_QUARTUS_VERSION/ ) { my @originalqarray = ( split / +/, $readlineqo ); $originalquartus = $originalqarray[3]; print "\nthe original quartus $originalquartus\n"; } if ( $readlineqo =~ /LAST_QUARTUS_VERSION/ ) { my @latestqarray = ( split / +/, $readlineqo ); $latestquartus = $latestqarray[3]; print "\nthe latest quartus $latestquartus\n"; } next if $readlineqo =~ /^ $/; } close($OFILE);
Also, you use glob in scalar context, which only returns one file at a time, but you call the results variable $synthfilelist and you output it as "input files in current directory" - this might lead to some confusion as it will only ever be one file per glob call.
Small update: Using a next statement as the very last thing in a loop is not necessary as the loop will go to the next iteration anyway, so unless you have code following it you can remove that line.
Hope this helps,
-- Hauke D
In reply to Re: searching two pattern sequentially from one file
by haukex
in thread searching two pattern sequentially from one file
by mrityunjaynath
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |