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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.