How do you create a Perl Program that asks a user to enter two numbers and assign those numbers to selections in a text and then reverse the text? I think I am supposed to use splice array and the reverse function but it is not coming out properly.

print "Enter a number:\n";
chomp ($number=<>);

print "Enter another number:\n";
chomp ($number=<>);

@array=(Yellow Green Brown Pink Black);
splice@array (0..4);
reverse@array:
print"The corresponding number and color)
I am supposed to do an inversion by asking the user to enter a two numbers and then invert the words in between them. i.e. If I choose 1 and then 4 I should get Pink, Brown, Green, Yellow.

http://www.cs.cmu.edu/afs/cs/usr/rgs/mosaic/pl-exp-arr.html

http://docstore.mik.ua/orelly/perl3/prog/ch09_01.htm

Read the above links and try the sample program

print "Enter a number:\n";
chomp ($number1=<>);

print "Enter another number:\n";
chomp ($number2=<>);

@array = qw(Yellow Green Brown Pink Black);

### Validate the input selection
unless ( $number1+ $number2 <= scalar @array )
{
	print "\n\t$number1, $number2 is a invalid Range selection.\n\tTry Again .... ";
	exit;
}

### Remove elements store into @splice in reverse order
@splice = reverse splice @array, $number1, $number2;

print "\n$_" for @splice;
commented: Great insight and detail +0

Thank you for your insight and the links really helped also.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.