Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Searching

Status
Not open for further replies.

Nuxx

Programmer
Joined
Mar 12, 2001
Messages
1
Location
PT
Hi!
I would like to know if anyone can help me build a PerlScrit to identify words inside a .txt file and write it in a HTML file.I´m a little rookie with perl

Thanks
 
Hello nuxx,
welcome to TTs. This is pretty basic stuff. You can see some decent tutorials at They have a pull down in the upper right corner. Go to tutorials and take your pick.

You want to open a text file,
search for a given word,
print that word into a new file.

Code:
#!perl
# open  a text file - store it in $buffer
open(IPF,&quot;<some_file_name&quot;) or 
            die &quot;Failed to open input file, $!\n&quot;;
while (<IPF>) { $buffer .= $_; }
close IPF;

# open an output file to write to.
open(OPF,&quot;>some_other_file_name&quot;) or 
            die &quot;Failed to open output file, $!\n&quot;;

# search for a given word
$search_word = 'the';  # probably find that one once of twice
while ($buffer =~ /\b$search_word\b/i) { print OPF &quot;the\n&quot;; }

close OPF;


HTH


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top