String operator

The concatenation operator . is used to add strings together:

print 'abc' . 'def';        # Prints abcdef
print $a . $b;              # Concatenates the string values of $a and $b

Binary x is the string repetition operator. In scalar context, it returns a concatenated string consisting of the left operand repeated the number of times specified by the right operand:

print '-' x 80;                           # Prints row of dashes
print "	" x ($tab/8), ' ' x ($tab%8);    # Tabs over

In list context, if the left operand is a list in parentheses, the x works as a list replicator rather than a string replicator. This is useful for initializing all the elements of an array of indeterminate length to the same value:

@ones = (1) x 80;           # A list of 80 1s
@ones = (5) x @ones;        # Set all elements to 5
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.205.232