Computer Science Canada Perl Sentance Generator |
Author: | Insectoid [ Wed Nov 19, 2008 4:36 pm ] |
Post subject: | Perl Sentance Generator |
So, today, I figured I'd get started on my Perl project, which happens to be a random paragraph generator. It has to be at least a little coherent, so it may take a while. Today I was able to create a random sentence generator, which I will expand to hold arrays of used words as well as the word files , a subject noun, and many sentence structures (so far, there is one). Yes, it is very funny. How to run: I figured maybe some people would like to try this thing out, even if they don't know Perl, so I figured I'd tell them. Linux: You probably know how to run this already. Mac: in the terminal, use the cd command to navigate to the folder directory (ex. cd desktop) and then type perl sentanceGenerator.pl. This will launch the script. You'll see the sentances in the terminal. Windows: You may have to download the perl interpreter. Then just double-click the script and it should launch in the command window. Some computers automatically close the command line after the script is run, so you may be unable to see the hilarious sentences. |
Author: | Tony [ Wed Nov 19, 2008 5:21 pm ] |
Post subject: | RE:Perl Sentance Generator |
You shouldn't be using "magic numbers" -- every time you edit your list of nouns, you'd have to modify every instance of "922". Use constants. Better yet -- just count the number of lines in the source file. You could also capitalize your leading articles in the script, instead of having two copies of essentially the same words. In more abstract terms -- have you looked into using Context Free Grammar for generating your sentences? |
Author: | wtd [ Wed Nov 19, 2008 9:41 pm ] |
Post subject: | RE:Perl Sentance Generator |
Try using "my" to scope your variables. |
Author: | Insectoid [ Thu Nov 20, 2008 12:19 pm ] |
Post subject: | RE:Perl Sentance Generator |
Tony- That is on my list of things to do, at the time of coding, I didn't know how to count lines. Is there a pre-defined function to find the number of lines in a file, or would I have to use a loop/counter/eof combination? "capitalize on leading articles..." Um...can you dumb that sentence down a bit ![]() Context free grammar: Exactly what I was looking for. wtd- I think I may use the 'strict' module to make debugging easier, which will force me to use 'my'. O/T, right now I'm watching the movie 'bowling for columbine'. Heavy stuff. Good film. |
Author: | Insectoid [ Fri Nov 21, 2008 1:21 pm ] | ||
Post subject: | RE:Perl Sentance Generator | ||
okay, I've hit a snag. I'm working on making the program decide weather or not to include an adverb in the sentence, and if it chooses to, then use a random adjective. [A snippet of] My code:
It works without the second 'if', but displays an extra space between words. I tried using other if structures ( if <condition> {#block}) but that didn't work either. I tried making $adverb1 = " ", or even '!', with the same results. EDIT: Wow, Compsci has Perl tags, I did not know that. Is this something Dan put in, or do these come with php? |
Author: | OneOffDriveByPoster [ Fri Nov 21, 2008 2:49 pm ] |
Post subject: | Re: RE:Perl Sentance Generator |
insectoid @ Fri Nov 21, 2008 1:21 pm wrote: EDIT: Wow, Compsci has Perl tags, I did not know that. Is this something Dan put in, or do these come with php? I don't think so. There is no syntax highlighting that I can see. |
Author: | Insectoid [ Fri Nov 21, 2008 3:17 pm ] |
Post subject: | RE:Perl Sentance Generator |
good point. I didn't even look at the syntax, I assumed that, because a syntax box was generated at all, a Perl syntax tag existed. Wow, now I feel dumb. Anywho, the problem has been fixed. |
Author: | Insectoid [ Mon Nov 24, 2008 1:06 pm ] | ||
Post subject: | RE:Perl Sentance Generator | ||
Okay, so I'm working on making this more portable, and I need to be able to find the directory that the perl file is in, so that it does not depend on hard-coding the file directory, which is a rather bad alternative. Is there a command that will return the directory? I tried
|
Author: | OneOffDriveByPoster [ Mon Nov 24, 2008 11:25 pm ] | ||
Post subject: | Re: RE:Perl Sentance Generator | ||
insectoid @ Mon Nov 24, 2008 1:06 pm wrote: Okay, so I'm working on making this more portable, and I need to be able to find the directory that the perl file is in, so that it does not depend on hard-coding the file directory, which is a rather bad alternative. I think this is what you want:
|
Author: | Insectoid [ Tue Nov 25, 2008 12:04 pm ] |
Post subject: | RE:Perl Sentance Generator |
This one gives me very strange output: /private/var/folders/zz/zZbbPMb4... This is what it returns for a folder on saved to my desktop. Jubberish. If it's saved on my desktop, I want it to return '/usr/desktop'. |
Author: | OneOffDriveByPoster [ Tue Nov 25, 2008 4:36 pm ] |
Post subject: | Re: RE:Perl Sentance Generator |
insectoid @ Tue Nov 25, 2008 12:04 pm wrote: This one gives me very strange output:
I suspect that you would find your desktop there./private/var/folders/zz/zZbbPMb4... This is what it returns for a folder on saved to my desktop. Jubberish. If it's saved on my desktop, I want it to return '/usr/desktop'. |