Hi prash_sri,

In your code, you are using open instead of opendir, this won't work. If you had warnings turned on, you would have been warned about this, see Use strict and warnings. Also, as documented in readdir, you should prepend the name of the directory to the filename, and note that it will return every entry in the directory, including subdirectories, which you can filter with perl's -f filetest operator, and including the special directories . and .., which you can filter with File::Spec's no_upwards (although the aforementioned -f test would filter them too). See the examples under readdir.

Trying to write a perl code which browses all the files recursively under a given input directory

If by recursively you mean that you want to look into subdirectories too, then I would recommend File::Find over readdir/opendir, or perhaps one of the easier-to-use modules File::Find::Rule, Path::Class's recurse function, or Path::Tiny's visit function. Personally I like Path::Class, but I can recommend any of the modules I mentioned here.

Regards,
-- Hauke D

Update: s/including \Kdir/subdir/


In reply to Re: Parse for a name after a keyword search in all the files, given directory as input by haukex
in thread Parse for a name after a keyword search in all the files, given directory as input by prash_sri

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.