Best to enclose this stuff in <CODE>..</CODE> tags so it looks like this...
$dir='C:/texts/';
opendir(directory,$dir) or die "cant";
while($file=readdir directory){
next if $file=~/^\./;
$rfname=$dir.$file;
# print "Found file: '$rfname'\n";
open (CONT, $rfname);
while (<CONT>){
if($_=~m/<a href="/index.pl?node=0-3&lastnode_id=19212">0-3</a>?<a
+ href="/index.pl?node=0-9%28th%29%3F%28st%29%3F%28nd%29%3F%28rd%29%3F
+&lastnode_id=19212">0-9(th)?(st)?(nd)?(rd)?</a>\s+(Jan(uary)?|Feb(rua
+ry)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sep(tember)?|Oct
+(ober)?|Nov(ember)?|Dec(ember)?)\s+<a href="/index.pl?node=0-9&lastno
+de_id=19212">0-9</a>?<a href="/index.pl?node=0-9&lastnode_id=19212">0
+-9</a>?<a href="/index.pl?node=0-9&lastnode_id=19212">0-9</a><a href=
+"/index.pl?node=0-9&lastnode_id=19212">0-9</a>/ig){
print "$file\t $_\n";
}
elsif($_=~m/(Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|
+Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?)\s+
+<a href="/index.pl?node=1-3&lastnode_id=19212">1-3</a>?<a href="/inde
+x.pl?node=0-9&lastnode_id=19212">0-9</a>(th)?(nd)?(st)?(rd)?\s+<a hre
+f="/index.pl?node=0-9&lastnode_id=19212">0-9</a>?<a href="/index.pl?n
+ode=0-9&lastnode_id=19212">0-9</a>?<a href="/index.pl?node=0-9&lastno
+de_id=19212">0-9</a><a href="/index.pl?node=0-9&lastnode_id=19212">0-
+9</a>/ig){
print "$file\t $_\n";
}
}
}
Looking at your code, it prints out the name of the file and the complete line when the line matches the regular expression. If that's not what you want then you'll need to capture part of the match using brackets and print the value of $1, not $_.
--
<a href="http://www.dave.org.uk><http://www.dave.org.uk>
European Perl Conference - Sept 22/24 2000
<http://www.yapc.org/Europe/>
In reply to Re: $_
by davorg
in thread $_
by Anonymous Monk
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|