Learning to write programs is not easy. In the beginning there is too much information, making it difficult to distinguish what is important and difficult to know what to do. To overcome these difficulties, you should follow an introductory course in programming. If you are studying on your own, you can find recommendations in Getting Started with Perl (I suggest you start with Where and how to start learning Perl). Find a tutorial introduction and follow it step by step. Don't rush. Study each example carefully to ensure you understand it before moving on. Be patient and diligent.

It is particularly difficult to learn how to break a complex problem down into simpler problems that can be solved more easily. I think How to Design Programs gives a gentle introduction. It uses Scheme rather than Perl, but the programming skills it teaches can be applied to other languages, including Perl.

You have been given very good guidance in other responses to your posts here. I wonder if you have read the documentation referenced in those responses. You should read the documentation carefully. If there is anything you don't understand, you can ask questions here.

In the mean time, here is a program which matches the strings in your file. You should compare this to the other answers you have been given. It is quite consistent and you should try to understand how to progress from the recommendations in those other answers to a program like this, step by step.

use strict; use warnings; # Read the entire file contents into $content my $file = 'test.txt'; open(my $fh, '<', $file) or die "$file: $!"; my $content = do { local $/; <$fh> }; close($fh); # Remove newlines and "\\n" sequences $content =~ s/\n|\\n//g; # Match strings my @matches = $content =~ m/saravanan/g; print "@matches\n";

In reply to Re^3: reading file by ig
in thread reading file by saranperl

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.