Hello gpssana,

Your question looks better now, but try to provide us with a bit more information. What is $word on your code, provide us with sample of desired output.

From what I see from your code, it is not clear for me what you are trying to do. Is it possible to write some high level description, (e.g. step one open my path, step two read directories and search for directories that start with (rev*), step three retrieve all html links files withing the directories file, etc, etc... I am just guessing here, I can not really understand what are you trying to achieve.

Also when you are trying to come up with a solution focus on the part of your code that is not working. What I mean comment out all parts that they do not play a vital role on your solution yet, focus on the line that you have a problem until you get the desired result and then proceed to the next step not all together.

Update: I checked the tutorial that I post yesterday, and I am wondering at this point if you read it. I am asking because more or less contains 80%-90% of your desired solution.

Sample of code modified to meet your criteria, taken from the tutorial.

# Accepts one argument: the full path to a directory. # Returns: A list of files that end in '.html'. sub get_new_htmls { my $path = shift; opendir (my $dh, $path) or die "Unable to open $path: $!"; my @files = map { $path . '/' . $_ } grep { !/^\.{1,2}$/ } readdir ($dh); # Rather than using a for() loop, we can just # return a directly filtered list. return grep { (/\.html$/) && (! -l $_) } map { -d $_ ? get_new_htmls ($_) : $_ } @files; }

I created a sample of index.html file trying to replicate your problem (sample of file bellow).

<html> <head> <title>Sample "Hello, World" Application</title> </head> <body bgcolor=white> <table border="0" cellpadding="10"> <tr> <td> <img src="images/springsource.png"> </td> <td> <h1>Sample "Hello, World" Application</h1> </td> </tr> </table> <p>This is the home page for the HelloWorld Web application. </p> <p>To prove that they work, you can execute either of the followin +g links: <ul> <li>To a <a href="hello.jsp">JSP page</a>. <li>To a <a href="hello">servlet</a>. </ul> </body> </html>

So I added the file in my directory and simply copied and applied minor minor modifications from the tutorial that I provide you (Directory Recursion).

Sample of code with output.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub get_new_htmls { my $path = shift; opendir (my $dh, $path) or die "Unable to open $path: $!"; my @files = map { $path . '/' . $_ } grep { !/^\.{1,2}$/ } readdir ($dh); # Rather than using a for() loop, we can just # return a directly filtered list. return grep { (/\.html$/) && (! -l $_) } map { -d $_ ? get_new_htmls ($_) : $_ } @files; } my @returned_files = get_new_htmls("/home/tinyos/Monks"); print Dumper \@returned_files; __END__ perl test.pl $VAR1 = [ '/home/tinyos/Monks/index.html' ]

Update your question based on the steps that I described above, also provide us with the error message that you are getting and the desired output. Sample of code that I provided you more or less should solve your problem by 90%.

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Unable to read the sub direcctory using perl? by thanos1983
in thread Unable to read the sub direcctory using perl? by gpssana

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.