Hello Sekhar Reddy,

Perl excels in text processing (note that PERL just does not exist: Perl is the language and perl is the program..).

Build up an array of files to search for. foreach one of these files open it and search in it.

You need to open the file in reading mode: see perlopentut but in short use the lexical filehandle form: foreach my $filename (@files) { open my $file_handle, '<', $filename or die "Unable to open $filename for reading!"; ...

Then you can use a while loop: see it at perlintro but pay attention to read just one line at time if the file is huge. Basically you have to do:

while (my $line = <$file_handle>){ chomp $line; ... }

After this you can use split to divide the line into fields and use a regular expression or eq to check the requested value. When this value is saved in a variable you can use it to do what do you prefere. Notice that if you need to save the result in the very same file you read, first close the filahandle and then reopen it in append mode using >>

Try the above and post here some code and tell us where you find problems.

Also be so kind to use <c> ..code tags..</c> around your code and data (you can also modify the above question).

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: search functionality in perl by Discipulus
in thread search functionality in perl by Sekhar Reddy

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.