On Mon, 24 Feb 2003, Gentile, Jeff wrote:
> Bill,
> Here is the -S prog code (only doing the technote dir at the
> moment) - notice that you had reccommended on friday I use a splice to
> skip my 8 line header... however I was getting erros with the "8"
> being beyond the array bounds with that mehtod
Is that the exact message? I'm not able to duplicate:
$ perl -lwe 'my @a=("hi"); my $x = join "", splice( @a, 8 )
So not every doc has 8 lines? I suppoes you could do
if ( @doc >= 8 ) {
...
}
> sub get_tech {
>
> opendir DH, $techdir || die "Open $techdir for read failed! $!";
> my @filelist = grep !/^\.\.?$/ && (/\.html?$/ || /\.txt$/), readdir DH;
Might also check that they are real files and not directories (although
it's probably not likely that foo.html will be a directory.
> closedir (DH) || die "Close $techdir failed! $!";
>
> foreach (@filelist) {
> $_ = "$techdir/$_";
> &tech_print($_);
> }
You realized that $_ is an alias for the actual element? So you are
modifying the array @filelist.
$ perl -lwe '@a=(1..5); for ( @a ) { $_ = "Hi/$_" }; print join "\n", @a'
Hi/1
Hi/2
Hi/3
Hi/4
Hi/5
I think you can just say:
tech_print("$techdir/$_") for @filelist;
or put the call to tech_print in a readdir() loop.
> my @line=<FH>;
> for (1..8) {
> shift @line;
> }
>
> foreach (@line) {
> $docsize .= $_;
> }
That's not really the doc size. Most would probably write:
my $doc = join '', @line;
or
my $doc = "@line"; # but adds spaces by default ($" var)
> my $size = length $docsize;
>
> print <<EOF;
> Path-Name: $filename
> Content-Length: $size
> Last-Mtime: $mtime
> Document-Type: $doctype
>
> EOF
> ;
^ - what's that for?
> print @line;
I don't really see the problem (since $, is undefined by default), but you
are using the length of $docsize, but printing @line. I'd just pick one.
Otherwise, if you redirect your script to a file and then edit out the
headers does the content-type match the file size? Actually that will be
hard to do because your editor might add a newline at the very end if one
doesn't already exist.
So maybe you are right you could print the trimmed doc to a file and see
what stat() reports for the file size. If perl's length is returning
chars and you have multi-byte chars then you will either need to convert
to 8859-1 in perl or get perl to report the correct length.
I do not know enough about Perl's support of Unicode to know if that's the
likely problem or not.
--
Bill Moseley moseley@hank.org
Received on Mon Feb 24 16:14:25 2003