CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



dossantos17
New User

Jul 2, 2015, 1:03 PM

Post #1 of 2 (2190 views)
substr() and reverse() functions Can't Post

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

Post #2 of 2 (2152 views)
Re: [dossantos17] substr() and reverse() functions [In reply to] Can't Post

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;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives