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 "The  result 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 "The  result is $result_c_string.\n";
#######################
#######################
$result_d_string = ($b_string . " " )x $ a_value;
print "The  result 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
The  result is heweiheweihewei.
The  result is hewei hewei hewei .
The  result is hewei hewei hewei .

你可能感兴趣的:(C++,c,C#,perl)