Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Adding items to arrays: best approach?

by soonix (Canon)
on May 28, 2020 at 08:38 UTC ( #11117391=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11117391]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2021-02-27 17:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?