I believe the pack function is implemented in C so I don't know how much faster you can write it...
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Su, Yu (Eugene) Sent: Tuesday, March 13, 2007 3:14 PM To: [email protected] Subject: RE: how to make it to run faster Hi all, I wrote a script to update a binary data file. The file is a 2048x2048 unsigned-short array encoded in little-endian + 8K header. All values should be even. However, there are some data corrupted with odd values. The task is to set all odd numbers to 1. I wrote a simple script which did the job, but it was too slow. It took over 40 seconds on my 5 year old PC. I wonder if there is better way to make it run faster. Thanks for help. -Eugene #### code snippet ############# use strict; use warnings; my $header; my $header_size=8*1024; my $body; my $body_size=2048*2048*2; my $image=$ARGV[0]; open(FH, "+<$image") or die "\nCan not open $image for updating: $!\n"; read(FH, $header, $header_size) == $header_size or print "\nshort read: $!\n"; read(FH, $body, $body_size) == $body_size or print "\nshort read: $!\n"; my $body_new; my $p; foreach $p (unpack("S*",$body)) { if ($p&1) {$p=1}; $body_new=$body_new.pack("S",$p); # packing is slow ~40 seconds } seek FH, 0, 0; print FH $header, $body_new; close(FH); _______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
