I suggest you take a look at perldoc -f open and your questions should be answered.
While it's possible in shells to use exec to reopen descriptors, Perl's exec is a different beast. You'll either replace your running program with a very short lived shell, or you'll spawn a child shell which won't affect the parent process' file descriptors in any way.
The example he gave was using shell redirection to capture the output of his script. And even so, it's overkill to spawn another shell when a simple { open( my $fh, ">", $newfile ) or die "open $newfile: $!\n" } would suffice.
Huh?!? Low and behold I'd just point him to
my %fh;
open $fh{$_}, '>', $_
or die "Can't open `$_': $!\n"
for @many_files;
# if they're not TOO many ;-)
tirwhan is right, but his link is taking forever to load, at least for me, so I'll add a little more information. Basically, you're looking for information on filehandles. You can open a file in output mode by doing something like open MYHANDLE, '>', $filename or die $!; and then you can write stuff to that open file with something like print MYHANDLE $stuff;
To create multiple files, just do that repeatedly. Some wording in your question leads me to believe you already know a way to do something repeatedly.
perlmonks.org content © perlmonks.org and bart, blazar, Fletch, idle, jonadab, tamaguchi, tirwhan
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03