Hi,
First of all, I´m a total newbie to perl, but have make some progress the latest week.
What I have done so far is a script that take a big textfile and change values in it.
The it cut up the textfile to multiple files to have files that not exceed 30000 lines. But my problem is that I also want to add a header and footer to each file. The header and footer include multiple lines.
This is my code so far:
open IN, "+<infil.txt" or die $!;
@file = <IN>;
seek IN,0,0;
foreach $file (@file){
$file =~ s/3/1/g;
$file =~ s/4/X/g;
$file =~ s/5/2/g;
print IN $file;
}
close IN;
open IN, "<infil.txt" or die $!;
$line_num=0; $file_num=0;
open OUT, ">>nextfile".$file_num.".str";
while (<IN>) { if ($line_num%30000==0) {
close OUT;
$file_num++;
open OUT, ">nextfile".$file_num.".str";
}
print OUT $_;
$line_num++;}
close OUT;
close IN;
Perhaps there is a way, so I dont have to open the sourcefile twice also?
First of all, I´m a total newbie to perl, but have make some progress the latest week.
What I have done so far is a script that take a big textfile and change values in it.
The it cut up the textfile to multiple files to have files that not exceed 30000 lines. But my problem is that I also want to add a header and footer to each file. The header and footer include multiple lines.
This is my code so far:
open IN, "+<infil.txt" or die $!;
@file = <IN>;
seek IN,0,0;
foreach $file (@file){
$file =~ s/3/1/g;
$file =~ s/4/X/g;
$file =~ s/5/2/g;
print IN $file;
}
close IN;
open IN, "<infil.txt" or die $!;
$line_num=0; $file_num=0;
open OUT, ">>nextfile".$file_num.".str";
while (<IN>) { if ($line_num%30000==0) {
close OUT;
$file_num++;
open OUT, ">nextfile".$file_num.".str";
}
print OUT $_;
$line_num++;}
close OUT;
close IN;
Perhaps there is a way, so I dont have to open the sourcefile twice also?