Monday, January 3, 2011

Perl: x operator

print "Test 1:\n";
@myarray = ("Hello", "World");

@array2 = ((@myarray) x 5);
print join(", ", @array2), "\n\n";


print "Test 2:\n";
@array3 = (@myarray x 5);

print join(", ", @array3), "\n\n";


print "Test 3:\n";
$string = "oncatc";

print (($string x 6), "\n\n");


print "Test 4:\n";
print join("\n", (("hello") x 5)), "\n\n";


print "Test 5:\n";
print join("\n", ("hello" x 5)), "\n\n";
OUTPUT:
Test 1:
Hello, World, Hello, World, Hello, World,
Hello, World, Hello, World


Test 2:
22222

Test 3:
oncatconcatconcatconcatconcatconcatc

Test 4:
hello
hello
hello
hello
hello


Test 5:
hellohellohellohellohello

No comments: