Gossamer Forum
Home : General : Perl Programming :

search directory

Quote Reply
search directory
Hi everybody,
I'm new to perl.
I wonder if anybody can help me out for a bit
My problem is this:
First of all I write a short story.
I then want to extract all the nouns from the short story and replace them with a blank space and display this to the screen.
It's here that i need the help!!
I was thinkin of doing it this way:
I store all nouns in a directory/database.
i then write some perl script which will take in my story, scan through it and if a word appears in the story which is also in the directory replace it with a blank space.Smile
This willthen be printed to the screen.
Does anybody know the code to do this??
Thanks in advance
Quote Reply
Re: [betty] search directory In reply to
Please read the description of this forum. You'll notice it isn't for general perl questions.

This is the forum you want:

http://gossamer-threads.com/...gforum.cgi?forum=14;

You may as well continue here though and a staff member will move the post.

A primitive example is:

Code:
my @nouns = qw/paul bob bill ben/;
my $string = 'Paul went to see Bob but Bill and Ben fell off a cliff';

foreach my $noun (@nouns) {
$string =~ s/$noun/ /ig;
}

For your situation you'd probably want to open your file and use a while loop depending on the amount of nouns you are storing.

Last edited by:

Paul: Dec 5, 2002, 9:17 AM