Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: perl experts .. plz

by CountZero (Bishop)
on Mar 21, 2016 at 19:50 UTC ( [id://1158457]=note: print w/replies, xml ) Need Help??


in reply to perl experts .. plz

Further to the comments already given, your program is a very naive implementation of a conjugation script. Of course, it will give the wrong answer for lots of more or less irregular verbs. So even when you correct all the syntax errors, it will still not run "correctly" in the sense that it will not give you the right answers.

And yet, no need to despair or re-invent the wheel when CPAN will provide you with such nice modules as Lingua::EN::Conjugate:

use Modern::Perl qw/2015/; use Lingua::EN::Conjugate qw/conjugate/; while ( my $verb = <DATA> ) { chomp $verb; for my $pronoun (qw/I you he we you they/) { say conjugate( verb => $verb, pronoun => $pronoun, allow_contractions => 1, tense => 'present', ); } say '---------------------'; } __DATA__ walk hear be have go try sing may
Output:
I walk you walk he walks we walk you walk they walk --------------------- I hear you hear he hears we hear you hear they hear --------------------- I'm you're he's we're you're they're --------------------- I've you've he's we've you've they've --------------------- I go you go he goes we go you go they go --------------------- I try you try he tries we try you try they try --------------------- I sing you sing he sings we sing you sing they sing --------------------- I may you may he may we may you may they may ---------------------

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^2: perl experts .. plz
by blueberry (Initiate) on Mar 21, 2016 at 20:18 UTC
    Sounds great .. but am afraid my teacher won't allow working on another version of the program. i don't know.. is there any other possible way to run it correctly on my current version.. and one more thing i forgot to mention in his question he wrote:" The first script conjugates a verb in present simple".. not in the past

      If you could explain, line by line, what your rationale is for the code you wrote, then perhaps we could be of further assistance in facilitating your learning process. I could write the thing for you in a couple of minutes. I've already devoted more time than that to trying to guide you in the right direction instead -- I feel no compelling need to write five lines of code that you can turn in to your teacher. My motivation is to help a newcomer get the sort of start with Perl that he or she will be able to build upon, and just writing some code for you, though it would save you and I both time this time around, won't contribute toward you becoming proficient with Perl, won't prepare you for the next assignment, and won't start someone on the path toward becoming a Perl user as time goes by.

      By you going through the process of explaining line by line why you made the choices you did in writing the code, we can better understand your thought-process, and we will be able to provide you useful insights. In particular, I'd like to know if it is dictated by the assignment itself that you use split, shift, pop, and a C-style for loop. If not, those are odd choices. Was it specified in the assignment that you use a single array to represent both the tenses and the suffixes? Again, a strange choice. But we really don't know which of your design choices are required elements in the assignment, and which are all yours. ...and if all yours, why.

      The most immediate problem is that you left off a closing curly brace. Curly-braces are almost always supposed to match, a left needs a corresponding right. Same with parenthesis and square brackets. If you add that to the end of your script where it belongs, the script should compile but still won't work, for some of the other reasons I enumerated in an earlier post.

      Have you read perlintro? You've spent more time fiddling with code and posting here than it takes to read perlintro, and it contains about 90% of what you would need to complete your assignment. After doing that, think it through; think to yourself, "How would I solve this with pencil and paper?" Your code doesn't demonstrate that thought process. Instead, it seems more like you pulled elements out of your lecture notes and inserted them into the code without understanding what they do. Once you have a concept of how it might be solved with pencil and paper, start writing code that does that, and add nothing that doesn't move you toward that goal... well nothing aside from strict and warnings.


      Dave

        thank you very much .. and i do apologize again
      The script I wrote conjugates the verbs in the present tense. What makes you think it conjugates the verbs in the past tense? It would be trivially easy to make it conjugate the verbs in the past tense (just change "present" to "past" in my program) but that is not the issue.

      The issue is - in my opinion - that even if you make your program run, it will still not run correctly, as it does not take into account how to deal with irregular verbs or certain well-known grammatical exceptions. If you wish to take care of that, then you will end up with a program very similar to mine.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics

        The point here is not conjugating verbs. The student has been presented with a simplistic problem in order to develop skills in handling strings and arrays using Perl. Let's get him up to speed on for and split. If he can't master those, CPAN won't be of much use to him.

        But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      It most certainly will not handle the verb 'be'.

        It won't even handle regular verbs ending in "y".

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1158457]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-11-12 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (39 votes). Check out past polls.