in reply to Join with x operator
Hello sneaky,
As everyone explained the difference lies on the parenthesis, on how you use it. It can have different affect on your script.
Since I am also relatively new to Perl I am also a more visual guy that a reader. So most of the time I create small scripts to help me understand how they operate.
This is a sample of code that simply puts numbers on the strings as process repeats its self through the x (multiplier). This shirt example maybe will help you to observe what happens on the script with different parenthesis.
#!/usr/bin/perl use strict; use warnings; print "Test 4:"; foreach $_ (0 .. 5) { print join("\n", (("hello[$_]") x $_)), "\n\n"; } print "Test 5:"; foreach $_ (0 .. 5) { print join("\n", ("hello[$_]" x $_)), "\n"; }
Output of the code:
Test 4: hello[1] hello[2] hello[2] hello[3] hello[3] hello[3] hello[4] hello[4] hello[4] hello[4] hello[5] hello[5] hello[5] hello[5] hello[5] Test 5: hello[1] hello[2]hello[2] hello[3]hello[3]hello[3] hello[4]hello[4]hello[4]hello[4] hello[5]hello[5]hello[5]hello[5]hello[5]
Maybe the foreach function you have not heard about it yet. But soon when you will reach the loops you will read about it, but in short what it does is simple put one by one the elements that you specify in the parenthesis (0 .. 5).
I hope that I did not confuse you more that tried to help you understand.
|
|---|