File handle arrays in PERL

# for personal notes

@group=(0,1,2,3,4);

# generate files and file handles
foreach $i (@group){
$train[$i]=”train_$i.txt”; # file name
$FILE[$i]=”FILE”.”$i”; # file handle
open $FILE[$i],”>$train[$i]” or die;
}

# write to file
foreach $i (@group){
print {$FILE[$i]} “test\n”;
close $FILE[$i];
}

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *