in reply to Adding items to arrays: best approach?
I'd definitely prefer push (inverse of pop) for appending arrays and it's friend for prepending arrays, unshift (inverse of shift) .
Slight improvement to your last example:
Better (IMO):push(@inputfiles, qq{$inputPathPrefix/test4.xml}); push(@inputfiles, qq{$inputPathPrefix/test5.xml}); push(@inputfiles, qq{$inputPathPrefix/test6.xml}); push(@inputfiles, qq{$inputPathPrefix/test7.xml});
The rub with qw// is that there's no variable interpolation. This means the following is treated literally,my @files = (qw/test4.xml test5.xml test6.xml test7.xml/); # assumin +g you know $inputPathPrefix will be the same for all of them push @inputfiles, @files;
is equivalent to:my @files = (qw{$inputPathPrefix/test4.xml $inputPathPrefix/test5.xm +l $inputPathPrefix/test6.xml $inputPathPrefix/test7.xml});
There is probably a lot of ways to do this idiomatically, the above is just an example of where I'd tend to go with it.my @files = (q{$inputPathPrefix/test4.xml}, q{$inputPathPrefix/test5 +.xml}, q{$inputPathPrefix/test6.xml}, q{$inputPathPrefix/test7.xml});
|
|---|