Hi all,
I wrote a script to search a pattern in input file and if pattern does not found in input file ,print that pattern in to output file.

The input file is
--------------------------------------------------------
1999-1011ğAll the flowers of tomorrow are in the seeds of today.
2000-1209ğI saw this article posted on another site and wanted to share it with everyone at TSDN. Please read this article and post your thoughts.
1999-1041ğAll the flowers of tomorrow are in the seeds of today.
2000-1367ğI saw this article posted on another site and wanted to share it with everyone at TSDN. Please read this article and post your thoughts.
2000-6646ğI saw this article posted on another site and wanted to share it with everyone at TSDN. Please read this article and post your thoughts.
2000-6463ğI saw this article posted on another site and wanted to share it with everyone at TSDN. Please read this article and post your thoughts.
----------------------------------------------------------
The pattern i want to find is 1999-1041
The script I wrote is-
open (RD, "input.txt") or die; @Read = <RD>; close (RD); open (WR2, ">>output.txt") or die; $count=0; $C="1999-1041"; for ($read=0; $read <= $#Read; $read++) { if($Read[$read] !~ /$C/) { $count++; print WR2"$count=$C\n"; } }

---------------------------------------------
The output I got is

1=1999-1041
2=1999-1041
3=1999-1041
4=1999-1041
5=1999-1041

That means it search 6 lines in input file and found 5 lines which does not contain pattern,thats why it prints pattern 5 times to output file.
But actually the required output is none as pattern is present in input file.

Need guidelines regarding this ..

--Mahesh

In reply to Need help regarding "search in file" by mpatharkar

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.