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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

splitting texts into words

Status
Not open for further replies.

zumbabumba

Technical User
Mar 4, 2008
8
IT
Hi there,
I'm new to perl. I wrote a script to split two pieces of poetry into words, but something wrong happen. Here is the .txt file to be processed:

Text 1.
line 1. Tiger, Tiger, burning bright
line 2. in the forest of the night

Text 2.
line 1. To be, or not to be
line 2. that is the question

Here is my script:
Code:
#!/usr/local/bin/perl
print "file name: ";
$my_file = <STDIN>;
open(FILE, "< $my_file") || die "Error!\n\n";
while (!eof(FILE)) {
  $line = <FILE>;
  chop ($line);
  @currentline = split(/ +/, $line);
  foreach $word (@currentline) {
    print "$word \n" if $word !=~ m/^\d+/;
}
}
I don't want the numbers to be included in the print, that is why I added if $word !=~ m/^\d+/ at the end, but this doesn't work. Any idea?
Thank for your help!


 
Great! Thank you for your help. Now I'm going to work to the second part of my project, that is a script that makes a text index. Something like this:

INDEX

be 2, 1
bright 1, 1
burning 1, 1
forest 1, 2
in 1, 2
is 2, 2
night 1, 2
not 2, 1
of 1, 2
or 2, 1
question 2, 2
that 2, 2
the 1, 2; 2, 2
Tiger 1, 1
To 2, 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top