[EMAIL PROTECTED] wrote:
$hostname is set to whatever I need to inject by some code above this
part, and $search is the data I need to replace with $hostname (they
are always the same length, so it never changes the size of the
downloaded file).  The loop at the end is what I imagine needs to be
faster.  I'm not sure if it would be safe or possible to read in the
entire file in one block, then just work on that buffer... would
probably use up too much memory on the server if I did that.


Do you want to replace _every_ occurrence of $search with $hostname?

# Open the input file for reading
open IN, "< $infile"
    or die "Can't open $infile: $!";

# Our EXE is a binary file
binmode IN;

# Get the file info
my @info = stat(IN);
my $length = $info[7];
my $blksize = 1;

# Send the HTTP header
print "Content-type: application/octet-stream\n";
print "Content-Length: $length\n";
print "Content-Disposition: attachment; filename=\"webinst.exe\"\n";
print "\n";

# Make sure that the output is written in
# binary mode and buffered
binmode STDOUT;
select STDOUT; $|=1;

Don't do this.  STDOUT is already selected.  You don't have to select it unless 
you are using formats.

Don't set $|.  Most of the time this slows things down, not speed them up.


# This is used to track our progress while searching for $search
string.
my $sx = 0;

# Read each chunk of the input file
# and pass it to the browser
#  This will replace each occurance of '$search' with '$hostname'
#   as it sends the file.
my $buffer;
while (!eof(IN))
   {
   read(IN, $buffer, $blksize);

 $buffer =~ s{$search}{$hostname}g;

      print $buffer;
      }
   }

close IN;
exit 0;



--
Just my 0.00000002 million dollars worth,
 Shawn

"For the things we have to learn before we can do them, we learn by doing them."
 Aristotle

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to