
siskos1
Novice
Mar 12, 2010, 6:13 PM
Post #1 of 2
(5260 views)
|
how will i get rid of this --> ' <--
|
Can't Post
|
|
hi, i need some help. any help will be great. i am doing an exercise and it is; "read sentences from a text file and write the first letters of each word in each sentence and the number of words in the sentence to a text file. You will also convert the letters to uppercase. The sentences will end with dot." Sample input file (input.txt) The tanker traffic on the Bosphorus becomes more dangerous day by day. An earthquake in Turkey's Elazig Province kills more than fifty people. The Hurt Locker wins six Academy Awards including Best Picture and the first female Best Director. Sample output file (output.txt) TTTOTBBMDDBD 12 AEITEPKMTFP 11 THLWSAAIBPATFFBD 16 ---------- my code is; use strict; use warnings; open( IN, 'input.txt'); $/ = undef; my $string = <IN>; close (IN); $string =~ s/\b(\w).+?\b/\u$1/g; $string =~ s/\s//g; my @words = split (/\./,$string); open (OUT, '>output.txt'); foreach(@words) { my $a=length($_); print (OUT "\n$_ $a"); } close(OUT); ---------------- however output becomes like this; TTTOTBBMDDBD 12 AEIT'SEPKMTFP 13 THLWSAAIBPATFFBD 16 ------------ i want my code to eleminate " ' " (and the letter after that) in the first place. how can i change my $string =~ s/\b(\w).+?\b/\u$1/g; not to include them. and what is the logic behind it that . doesnt cover ' ? thanks to anyone who read till here.
(This post was edited by siskos1 on Mar 12, 2010, 6:16 PM)
|