in reply to Creating multiple files and writing in each file

Hi irthiza90, welcome to the Monastery!
#!/usr/bin/perl use warnings; use strict; my @fh; # will store the filehandles. # Open multiple files. for my $i (1 .. 10) { open $fh[$i], '>', "file-$i" or die $!; } # Write in each. Not sure whether it's simultaneous enough. for my $i (1 .. 10) { print {$fh[$i]} $i; }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Creating multiple files and writing in each file
by AppleFritter (Vicar) on Mar 13, 2015 at 10:51 UTC

    You can also use IO::Tee to create a handle that outputs to several files at once:

    #!/usr/bin/perl use strict; use warnings; use feature qw/say/; use IO::Tee; my @fhs = map { open my $fh, ">", "file-$_" or die $!; $fh } 1..10; my $tee = new IO::Tee(@fhs); say $tee "AppleFritter!";

      thank you, it works.