http://qs321.pair.com?node_id=11117391


in reply to Adding items to arrays: best approach?

In the final program or script, you probably won't list all those file names, but you'll read them e.g. from a config file or even calculate them, which more or less will lead to a loop, like this
use 5.011; use warnings; use Data::Dumper; my $inputPathPrefix = "C:/Temp/xml"; my @inputfiles; for my $i (1..7) { push(@inputfiles, $inputPathPrefix . "/test${i}.xml"); } say Dumper(\@inputfiles);
gives
$VAR1 = [ 'C:/Temp/xml/test1.xml', 'C:/Temp/xml/test2.xml', 'C:/Temp/xml/test3.xml', 'C:/Temp/xml/test4.xml', 'C:/Temp/xml/test5.xml', 'C:/Temp/xml/test6.xml', 'C:/Temp/xml/test7.xml' ];
In a loop, push is more or less the only method.

BTW, you can also push multiple values in one go, see push