I have a list of filenames. I have to create a file for each of those names, write lines to the various files (in no particular order), then close them.
How can I do that in perl? I envision something like the following code (which will not work in that form and give syntax errors):
my @names = qw(foo.txt bar.txt baz.txt);
my @handles;
foreach(@names){
my $handle;
open($handle, $_);
push @handles, $handle;
}
# according to input etc.:
print $handles[2] "wassup";
print $handles[0] "hello";
print $handles[1] "world";
print $handles[0] "...";
foreach(@handles){
close $_;
}
How can I do this right?