The concatenation operator (.) is documented in perlop. It evaluates its operands in scalar context, stringifies and concatenates what the operands returned, then returns the result of the concatenation. In scalar context, @array evaluates to the number of elements in the array.

$ perl -we'my @a=qw( a b c ); my $x = @a . "\n"; print $x' | od -c 0000000 3 \n 0000002

@array "\n" is not valid Perl. Below, I'll talk about @array, "\n" in case that's what you meant.

$ perl -we'my @a=qw( a b c ); my $x = @a "\n";' String found where operator expected at -e line 1, near "@a "\n"" (Missing operator before "\n"?) syntax error at -e line 1, near "@a "\n"" Execution of -e aborted due to compilation errors.

In scalar context, the list operator aka comma operator executes all but the last of its operands in turn (sometimes in void context, sometimes in scalar context) and discards what they return. It then executes that last operand and returns the result. In this case, this would mean that @array returns the number of elements it contains, that would get discarded, then it returns "\n".

$ perl -we'my @a=qw( a b c ); my $x = (@a, "\n"); print $x' | od -c Useless use of private array in void context at -e line 1. 0000000 \n 0000001

In list context, the list operator aka comma operator executes all of its operands in turn (in list context) and forms a list from the values they return. That list is then returned. In this case, this would mean that @array returns all of its elements. A value of "\n" is appended to that list, then the whole list is returned.

$ perl -we'my @a=qw( a b c ); my @x = (@a, "\n"); print "[$_]" for @x' + | od -c 0000000 [ a ] [ b ] [ c ] [ \n ] 0000014

My understanding is just that . is used to match single characters in regex.

Regex patterns have their own syntax.


In reply to Re: difference between @array."\n" and @array "\n" by ikegami
in thread difference between @array."\n" and @array "\n" by NileshJ

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.