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.

Seeking for Perl wisdom...on the process...not there...yet!

In reply to Re: Join with x operator by thanos1983
in thread Join with x operator by sneaky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.