Hi,
I've never looked at a perl script before, but I'd like to modify a fragment of a bigger program. So I'd like to ask you this:
sub RewriteFile {
my ($file, $tmpfile) = @_;
my $i;
my $temporary;
if (!open (IN, "$file")) {
print "Couldn't open input file $file\n";
return 0;
}
if (!open (TEMP, ">$tmpfile")) {
print("Couldn't open temporary file $tmpfile\n");
return 0;
}
binmode TEMP;
binmode IN;
while (<IN>) {
s/\r?\n$/\n/;
s/\r/\n/g;
$_ = &TabConversion($_);
# Walk through the line and see if it longer than MaxChars.
if (length($_) >= $MaxChars) {
print TEMP substr($_, 0, $MaxChars);
print TEMP "\n";
print TEMP substr($_, $MaxChars);
}
else {
print TEMP "$_";
}
}
print TEMP "\n";
close(IN);
close(TEMP);
return 1;
}
sub TabConversion {
my $line=shift(@_);
while($line=~/([^\t]*)\t/) {
my $spaces="";
my $spaceNO=$SpacesPerTab-(length $1)%$SpacesPerTab;
for (1..$spaceNO) {$spaces.=" ";}
$line =~ s/([^\t]*)\t/$1$spaces/;
}
return $line;
}
This script reads a text file, and writes a tmp file.
I'd like to just write line number 10 of that file. Can anybody help me with that?
thanks a lot in advance.
I've never looked at a perl script before, but I'd like to modify a fragment of a bigger program. So I'd like to ask you this:
sub RewriteFile {
my ($file, $tmpfile) = @_;
my $i;
my $temporary;
if (!open (IN, "$file")) {
print "Couldn't open input file $file\n";
return 0;
}
if (!open (TEMP, ">$tmpfile")) {
print("Couldn't open temporary file $tmpfile\n");
return 0;
}
binmode TEMP;
binmode IN;
while (<IN>) {
s/\r?\n$/\n/;
s/\r/\n/g;
$_ = &TabConversion($_);
# Walk through the line and see if it longer than MaxChars.
if (length($_) >= $MaxChars) {
print TEMP substr($_, 0, $MaxChars);
print TEMP "\n";
print TEMP substr($_, $MaxChars);
}
else {
print TEMP "$_";
}
}
print TEMP "\n";
close(IN);
close(TEMP);
return 1;
}
sub TabConversion {
my $line=shift(@_);
while($line=~/([^\t]*)\t/) {
my $spaces="";
my $spaceNO=$SpacesPerTab-(length $1)%$SpacesPerTab;
for (1..$spaceNO) {$spaces.=" ";}
$line =~ s/([^\t]*)\t/$1$spaces/;
}
return $line;
}
This script reads a text file, and writes a tmp file.
I'd like to just write line number 10 of that file. Can anybody help me with that?
thanks a lot in advance.