This script is from the book "VRML for the Internet" ( VRML: Browsing and Building Cyberspace ) by Mark Pesce, 1995. Although I have it, the cd-rom that included it will be in the garbage years ago ...
Its author is James Waldrop, and calls it "Datafat munger", a redundant precision eliminator, which just removes a few decimals, but a vrml file has hundreds. A compactor, so to speak, creating a new file with extension .new.
I have transcribed as it is printed and looked at a copy in English in case it was an erratum, and the codes are identical. IT DOES NOT WORK, and I remember that when I was young it was executed (the one of the CD-ROM).
I get syntax error by the \t
modifier on line 23.
Where is the error?
for ($x=-1; $x++ < $#ARGV; ) {
$file = $ARGV[$x];
if (! (-e $file) ) {
print "$file not found, skipping...\n";
next;
}
&convert($file);
}
exit;
sub convert {
local ($file)= @_;
open (OLD, $file) || die "Couldn´t open $file: $!\n";
open (NEW, ">$file.new") || die "Couldn´t open $file.new: $!\n";
while (<OLD>) {
$line = $_;
if (/Normal/) { while (<OLD>) { last if /}/; } Sline => ""; }
if (/normalIndex/) { while(<OLD>) { last if /[]]/; } $line = ""; }
$line =~ s/[-+]?[0-9]\.[0-9]+e[+-][0-9]+/0/g;
$line =~ s/([-+]?[0-9]+\.[0-9]{2})[0-9]+/$1/g;
$line =~ sfor ($x=-1; $x++ < $#ARGV; ) {
$file = $ARGV[$x];
if (! (-e $file) ) {
print "$file not found, skipping...\n";
next;
}
&convert($file);
}
exit;
sub convert {
local ($file)= @_;
open (OLD, $file) || die "Couldn´t open $file: $!\n";
open (NEW, ">$file.new") || die "Couldn´t open $file.new: $!\n";
while (<OLD>) {
$line = $_;
if (/Normal/) { while (<OLD>) { last if /}/; } Sline => ""; }
if (/normalIndex/) { while(<OLD>) { last if /[]]/; } $line = ""; }
$line =~ s/[-+]?[0-9]\.[0-9]+e[+-][0-9]+/0/g;
$line =~ s/([-+]?[0-9]+\.[0-9]{2})[0-9]+/$1/g;
$line =~ s%pre%\.00/0/g;
$line =~ s/[ ]+/ /g;
$line =~ s/[\t]+/ /g;
$line =~ s/^ //g;
print NEW $line;
}
close OLD;
close NEW;
}
\.00/0/g;
$line =~ s/[ ]+/ /g;
$line =~ s/[\t]+/ /g;
$line =~ s/^ //g;
print NEW $line;
}
close OLD;
close NEW;
}
Thank you if you can help me.