in reply to Loading multiple identical variables in array with multiplication variable

Yes, surround the strings with parens to enforce list repetition ( vs string)

edit

DB<126> @arr = (("A") x 2, ("T") x 2, ("C") x 3, ("G") x 3); => ("A", "A", "T", "T", "C", "C", "C", "G", "G", "G")

update

see perlop#Multiplicative-Operators "repetition operator" for details

Binary "x" is the repetition operator. In scalar context or if the left operand is not enclosed in parentheses, it returns a string consisting of the left operand repeated the number of times specified by the right operand. In list context, if the left operand is enclosed in parentheses or is a list formed by "qw/STRING/", it repeats the list. If the right operand is zero or negative, it returns an empty string or an empty list, depending on the context.

but I have to admit it sounds confusing ... :)

update

hmm should maybe be rephrased:

DB<129> $arr = ("G") x 3; => "GGG"

always a string in scalar context!

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

Replies are listed 'Best First'.
Re^2: Loading multiple identical variables in array with multiplication variable
by Jeri (Scribe) on Sep 24, 2014 at 16:53 UTC
    perfect thanks.