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
givesuse 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);
In a loop, push is more or less the only method.$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' ];
BTW, you can also push multiple values in one go, see push
In Section
Seekers of Perl Wisdom