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!
|