First off, you should be use some sort of HTML parser. What if my HTML file is of the form:
You'd never find "Blahblah".<TITLE> Blahblah </title>
Secondly, the fix you're looking for is
Note the backslash in front of the slash for the first one and the different regex delimiters for the second.if ($line =~ /<TITLE(\w+)<\/TITLE>/i) ---- if ($line =~ m#<TITLE>(\w+)</TITLE>#i)
I have no idea what you're trying to do in your second regex. Why are you looking for the end of line with '$' before your line is done?
Also, use indentation. Your code should look something like:
See how much easier that is to read?use File::Find; sub wanted { if( -f $_ = '*.htm* ) { open ( F, $_ ) or die $/, $/; while( defined( $line = <F> ) ) { if($line =~ /<TITLE>(\w+)</TITLE>/i) { print "FILE = $_ and TITLE = $1\n"; } elsif( $line =~ /<title>(.*$)<title>/i) { print "FILE = $_ and TITLE = $1\n"; } } close F; } } find( \&wanted, "." );
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
In reply to Re: Finding data
by dragonchild
in thread Finding data
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |