It looks like you are not really assigning a value to $_. Try it like this:
$_ = "Tim created the ...";
while ( /\bit (.*?)[.?!]/ig ) {
print "\n$1\n";
}
Once you see that this works more or less the way you want, try putting the data into a file -- call it "test.txt" -- and make the script look like this:
while (<>) {
while ( /\bit (.*?)[.?!]/ig ) {
print "\n$1\n";
}
}
(That is, remove the long data string from the script, and just have the two while loops as shown.)
If the script is stored in a file called "test.pl", you can now run it on your test data file using the following command line:
perl test.pl test.txt
Then start spending some time reading some of the basic tutorials and introductory books about Perl, and study the example code in those sources to get more familiar with the syntax. |