frenchcr
February 2nd, 2008, 07:50 AM
Howdy,
I have a file with 2968 commands (on different lines and all ending with \n) in a file named "subfile".
I would like to put each of the commands in their own file (i.e. subfile0, subfile1, ... , up to subfile2967)
Heres how far ive got.....
#!/usr/bin/perl -W
$NumOfSim = shift(@ARGV);
chomp($me = `id -un`);
$PATH = "/home/$me/src/Tc/Scheme4";
$DIR = "$PATH/Simulation$NumOfSim";
$DIR2 = "$PATH/Simulation$NumOfSim/subfile_split";
open(FILEIN,"<$DIR/subfile") || die "Cannot open subfile\n";
@row_data = <FILEIN>;
close FILEIN;
for($j=0;$j<2968;$j++) # jmax = number of job subs
{
open(FILEOUT,">$DIR2/subfile$j") || die "Cannot open subfile$j \n";
foreach $line(@row_data)
{
chomp($line);
$cmd = "$line ";
print FILEOUT "$cmd \n";
}#$line
}
...when i try to print each command to its own file, ALL the commands go to ALL the files ??
Any ideas??
I have a file with 2968 commands (on different lines and all ending with \n) in a file named "subfile".
I would like to put each of the commands in their own file (i.e. subfile0, subfile1, ... , up to subfile2967)
Heres how far ive got.....
#!/usr/bin/perl -W
$NumOfSim = shift(@ARGV);
chomp($me = `id -un`);
$PATH = "/home/$me/src/Tc/Scheme4";
$DIR = "$PATH/Simulation$NumOfSim";
$DIR2 = "$PATH/Simulation$NumOfSim/subfile_split";
open(FILEIN,"<$DIR/subfile") || die "Cannot open subfile\n";
@row_data = <FILEIN>;
close FILEIN;
for($j=0;$j<2968;$j++) # jmax = number of job subs
{
open(FILEOUT,">$DIR2/subfile$j") || die "Cannot open subfile$j \n";
foreach $line(@row_data)
{
chomp($line);
$cmd = "$line ";
print FILEOUT "$cmd \n";
}#$line
}
...when i try to print each command to its own file, ALL the commands go to ALL the files ??
Any ideas??