Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Nth position of array determind by <>

by Marshall (Canon)
on Apr 24, 2016 at 15:05 UTC ( [id://1161361]=note: print w/replies, xml ) Need Help??


in reply to Nth position of array determind by <>

Trying to learn programming on your own is a daunting task. I suggest getting a beginning book, perhaps "Perl for Dummies". I think you can get a used copy of this at a reasonable price. There are other books, but a lot of them start off too quickly for someone with no programming experience. I congratulate you on trying to learn a new skill.

Here is some code for you to play with. There are many flaws in this, but I think you just wanted a simple demo of an input loop.

#!/usr/bin/perl use warnings; use strict; my $numbers = "2 1 3 4 5"; my @numbers = split(' ', $numbers); print "numbers are: @numbers\n"; my $input; print "Enter numbers 1-5, q to quit:\n"; while ($input =<STDIN>, $input !~/q/i) { chomp $input; #needed to get rid of line ending print "the $input th num: $numbers[$input-1]\n"; } print "program completed\n"; __END__ numbers are: 2 1 3 4 5 Enter numbers 1-5, q to quit: 3 the 3 th num: 3 5 the 5 th num: 5 q program completed
Update: saw this free beginning Perl online book. Price is right! Still goes very quickly for a non-programmer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-26 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found