a13698822086 发表于 2017-5-17 07:39:34

Perl-标量数据

Perl-x

字符串重复操作符:x
比如:"fred" x 3
输出: fredfredfred

#!perl
#Learing Perl
#Chapter 2
#Exercise2_5
#Written by HEWEI
#Date:2011 03 22
########################
#User input the value
#$a_value = <STDIN> ;
print "Please input the number of a_value\n";
chomp($a_value = <STDIN> );
print "The a_value is $a_value\n";
#########################
print "Please input the string of b_value\n";
chomp($b_string = <STDIN> );
print "The string is $b_value\n";
$result_b_string = $b_string x $ a_value;
print "Theresult is $result_b_string.\n";
#########################
########################
$c_string = $b_string . " ";
########################
########################
#$result_b_string = $b_string x $ a_value;
$result_c_string = $c_string x $ a_value;
#print the result
print "Theresult is $result_c_string.\n";
#######################
#######################
$result_d_string = ($b_string . " " )x $ a_value;
print "Theresult is $result_d_string.\n";
#end

输出结果:
Please input the number of a_value
3
The a_value is 3
Please input the string of b_value
hewei
The string is
Theresult is heweiheweihewei.
Theresult is hewei hewei hewei .
Theresult is hewei hewei hewei .
页: [1]
查看完整版本: Perl-标量数据