in reply to Nth position of array determind by <>
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.
Update: saw this free beginning Perl online book. Price is right! Still goes very quickly for a non-programmer.#!/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
|
|---|