use strict;
use warnings;
my $DATAIN_FILE = "test.txt";
open my $data_in_fh, "<", $DATAIN_FILE
or die "Cannot open '$datain_FILE' for reading - $!";
while (<$DATAIN_FILE>) {
chomp;
$var = $_;
@var= split ("|",$_);
#Create and put value of filename
my $fname_out = var[0];
#Spit data to have file name and information to put in the file
my ($fname;$data_out_fh) = split /|/, $;
#if name of file fname_out the same with the name of first value in the
line fname print line in the file
if (fname=fname_out)
{open $data_out_fh, ">", "$fname.txt"
or die "Cannot open '$fname.txt' for writing - $!";
print {$fname_out} "$data_out_fh\n";
}
}
else
{
#if fname not the same with firts value in the line then create a new file
with this name of firts value in line and add line in the file
$fname_out=$fname
open $data_out_fh, ">", "$fname.txt"
or die "Cannot open '$fname.txt' for writing - $!";
print {$fname_out} "$data_out_fh\n";
}
close($data_out_fh);