You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Alexander Charbonnet <al...@charbonnet.com> on 2005/09/13 06:58:32 UTC

Re: Custom deflation gzip filter [mp2] [SOLVED]

In case anyone cares, I finally realized what the difference is between these 
two code snippets: context.  In array context, flush() returns an array 
containing the output as well as the return code.  In scalar context, flush() 
returns just the output.  The print function, of course, asks for an array.  
Kind of a "duh" moment.


On Saturday 27 August 2005 01:18 pm, Malcolm J Harwood wrote:
> On Friday 26 August 2005 06:25 pm, Alexander Charbonnet wrote:
> > It apparently works after I played with the code for the final flush. 
> > I'm not sure why, though.  There was only one change (below).  Anybody
> > see a significant difference?
> >
> >
> > In any case, I'll take it, since it works now.  :-)
> >
> >
> > ------Original (broken) code------------
> >         $f->print(join '',
> >                   $state_ref->{'handle'}->flush(),
> >                   pack("V V",
> >                            crc32($state_ref->{'body'}),
> >                            length($state_ref->{'body'})),
> >                 );
> > -------------------------------------------
>
> My guess is that the above evaluates the pack before the flush in order to
> pass the results to join(), so it's sending out the wrong length/crc.
>
> > ------Working code----------------------
> >         $final_output = $state_ref->{'handle'}->flush();
> >
> >         $f->print(join '',
> >                   $final_output,
> >                   pack("V V",
> >                            crc32($state_ref->{'body'}),
> >                            length($state_ref->{'body'})),
> >                 );
> > ------------------------------------------
>
> This forces the flush to be evaluated first.