Home: Perl Programming Help: Beginner:
substr() and reverse() functions



dossantos17
New User

Jul 2, 2015, 1:03 PM


Views: 2255
substr() and reverse() functions

Hi, i need som help, im new in programing,

the question I need to solve:

The scrambling should be achieved by reversing the
first and last $number characters of $string (in that order). To avoid giving any hints as to
the values used the scrambled string should appear all in lowercase. For example:
String=Babraham Number=2, Scrambed= abbrahma
String=Institute Number=3, Scrambled=snititetu
Hint: use the substr() and reverse() functions.

very happy if someone could help me Smile


Laurent_R
Veteran / Moderator

Jul 3, 2015, 12:00 AM


Views: 2217
Re: [dossantos17] substr() and reverse() functions

Hi,
hmm, this looks like a homework assignment, and this is really easy. Look at the perldoc for the two functions suggested (as well as the lc function for lower case).

To get you started, for the beginning of the string:

Code
my $start = substr $string, 2; 
$start = lc $start;
$start = reverse $start;

Or, all in one line:

Code
my $start = reverse lc substr $string, 2;