Perl & Binary Data (fwd)

abez abez at abez.ca
Tue Dec 17 11:39:49 CST 2002



-- 
abez----- ----- ------ - ------ -- ------------
http://www.abez.ca/ Abram Hindle (abez at abez.ca)
--- --- ------ --------- - - ------ --------abez

---------- Forwarded message ----------
Date: Mon, 16 Dec 2002 22:52:51 -0800 (PST)
From: abez <abez at abez.ca>
To: owner-victoria-pm at pm.org
Subject: Perl & Binary Data

I want to filter short integers in perl. I know I could do this in C or C++
easily but I want to do it in perl effectively. I think I'm taking a big hit
converting to and from binary to perl numbers and back again.
E.g.

in C

while (len = read(fd,(char*)buffer,size)) {
	for (i = 0; i < size/sizeof(short); i++) {
		buffer[i] = buffer[i]/2;
	}
	write(fd,(char*)buffer,size);
}

so far in perl I'm guessing

while ($len = sysread($fd,$buffer,$size)) {
	my @o = unpack("s*",$buffer);
	foreach (@o) {
		$_/=2;
	}
	syswrite($fd,pack("s*",$buffer,$size);
}

This seems really slow for datarates of 178kb/s

-- 
abez----- ----- ------ - ------ -- ------------
http://www.abez.ca/ Abram Hindle (abez at abez.ca)
--- --- ------ --------- - - ------ --------abez



More information about the Victoria-pm mailing list