zumbabumba
Technical User
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:
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!
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+/;
}
}
Thank for your help!