Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: perl experts .. plz

by davido (Cardinal)
on Mar 21, 2016 at 15:05 UTC ( [id://1158442]=note: print w/replies, xml ) Need Help??


in reply to perl experts .. plz

  • The input captured into $verb will probably end in a newline. You should use chomp to rid your string of that unwanted clutter.
  • Your split statement splits into void context (the return value is not captured), and the parameters are wrong; you certainly don't want to treat $verb as a pattern.
  • Your for statement increments $i before entering the loop, and never again. The $i++ should appear after the last semicolon, not before the first one.
  • Your second print statement includes $verb-3, which will result in -3 being printed, and if warnings are enabled, a warning being generated, because $verb will probably not contain anything resembling a number, so Perl will treat it as a zero in numeric context.
  • You are using @pronouns_ending to hold two types of data in a confusing way. Better to use an array of array-refs, or some data structure that better reflects the relationships of the data that are currently only represented by partitioning the array.
  • You lack a final }, preventing compilation.
  • You aren't using strict and warnings -- tools that will aid in preventing or discovering other common pitfalls.

Dave

Replies are listed 'Best First'.
Re^2: perl experts .. plz
by blueberry (Initiate) on Mar 21, 2016 at 19:39 UTC
    thank you Mr. davido, but again i don't get it .. it's supposed to be an easy question i know, but honestly am very week in perl.. would u plz help me correct and creat a script out of this:( using loop for) #.............................# @pronouns_ending=("i","you","he/she/it","we","you","they","","","","s","",""); print"Give a verb to be conjugated in present simple :\n\nVerb:\t"; $verb=<<>>; split $verb; print "\n"; for($i++;$i<4;){ print pop(@pronouns_endings)." ".$verb-3.shift(@pronouns_endings)."\n"; }
Re^2: perl experts .. plz
by blueberry (Initiate) on Mar 21, 2016 at 19:57 UTC
    Mr. Dave i tried to follow your instructions and that's what i got #..................# use strict; use warning; @pronouns_ending=("i","you","he/she/it","you","they","","","s","",""); print"remember :\n\nVerb:\t"; chomp $verb=<<>>; split $verb; print "\n"; for($i++;$i<4;){ print pop(@pronouns_endings($i))." ".$verb-3.shift(@pronouns_endings(i+5))."\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2025-12-05 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (83 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.