Perl:反转输入名称,大写第一个字母,小写最后一个字母

时间:2018-04-18 01:54:43

标签: perl

我目前正在编写一个脚本,询问用户的名字并反转输入,然后打印带有小写的最后一个字符和大写的第一个字符的字符串。如果我能在这里得到帮助,我会非常高兴。enter image description here

print "Please type in your first name here :";

my$name = <STDIN>;

chomp($name);

$function_applied_name = reverse($name);  #at this point Name becomes emaN

$chopped_last_character = chop($function_applied_name); #taking out the last N so that ema "N" 

$lower_cased = lc($chopped_last_character); #"N" becomes lower-cased letter so "n"

$pre_uppsercase_process = substr($function_applied_name,0,-1); # here picks "ema" from the string "emaN"

$upper_cased = ucfirst($pre_uppercase_process); #then upper-case the first character which is "E" so that the string becomes "Ema" here 

print "$upper_cased" . "$lower_cased" . "\n";

2 个答案:

答案 0 :(得分:1)

始终onClickUse strict;

Use warnings;

这将获取输入,反转字符串,转换为小写,然后将首字母大写。

答案 1 :(得分:-1)

我不知道你究竟在问什么可能会检查下面的简要代码:

arr = [1,3,2,4,5]
#counter for the array
arr_counter = 0

for ele in array:
    # check if end of list has been reached
    if (arr_counter+1) != len(arr):
        #put all your code here
        pass
    # increment the array counter
    arr_counter += 1