Results 1 to 2 of 2
I am trying to make a random sentence generator in perl.
So far I can loop it x times to make a fixed quantity of words, but I don't want ...
- 08-11-2010 #1Just Joined!
- Join Date
- May 2010
- Location
- uk
- Posts
- 20
perl match character
I am trying to make a random sentence generator in perl.
So far I can loop it x times to make a fixed quantity of words, but I don't want to do that.
Or I can let it go on until I hit ctrl-C :/
I want to have it so that when it reaches a word with a sentence terminating punctuation mark it stops.
My attempt to do that was with:
until ($last =~ m/[!\.\?]$/) {
<generate words for sentence>
}
This is doing the woooosh text until ctrl-C thing...
Sooooooo.... how can I do it right?
EDIT: Ok, that was actually working, the problem was something else.
Now however I am not sure how I can cut off everything after the punctuation mark (when it exists).
- 08-12-2010 #2
I don't understand your question. This should work:
This way, the last line will be checked against a regular expression that matches a period, question mark, or exclamation point at the end. If the line matches, we exit the loop.Code:while(1) { # generate text and store each line in $last last if $last =~ /[.?!]$/; }DISTRO=Arch
Registered Linux User #388732


Reply With Quote