Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials
( categories: | )

A useful method to initialize all the elements of an array with the same value is with the 'x' repetition operator.

The 'x' operator is mostly used in scalar context to build a string with a repeated pattern but, when used in a list context, it allows to set all the elements of an array with the same value.

Examples:
#-- initialixe @array with 50 zeroes
@array = 0 x 50;
 
#-- reset all elements to value '1'
@array = (1) x @array