Perl question relating to pattern substitution

-=Runaway Daemon=- frechett at boulder.Colorado.EDU
Sat Jan 5 16:10:35 AEST 1991


I am having some problems with the following perl script.  It is supposed to 
take a file with strings like A2448932B3F233490 which starts with 
%%HP        and the string itsself starts with "   and has a newline
every sixty characters and a " terminats it, and convert this mess into
a binary file that can be downloaded to the hp48sx calculator.  This script
was posted, with the statement that it works fine on the poster's system.
Unfortunately, I don't know what that was.  Here is the script and 
my comments after the @s.

#!/usr/local/bin/perl 
# unasc
# A perl program to extract a HP-48 binary from a text file containing a 
# ->ASC program. 
#
# Usage: unasc file > binfile
#
# Written by Wayne Scott  1990

while (<>) {
	next if (!(/%%HP/../"$/)); 	# Skip everything but program
	chop;				
	$file .= $_;		
}
@ I added the following two lines and commented out the one after that 
@ as my perl had no idea what to make of \w.
$file =~ s/"//g;
$file =~ s/%%HP//g;
# $file =~ s/.*"(\w*)\w\w\w\w".*/\1/;	# strip newlines, ", and CRC

@ This is the line that I am having problems with.. Simply, it replaces every
@ two characters with the string "pack(C,hex(\1.\2)"  whis is totally useless
@ as it is supposed to be converting ascii to binary.  
$file =~ s/(.)(.)/pack(C,hex(\1.\2))/eg;  # convert ascii to bin

print $file;

-----------------------------------------------------------------
The problem is that my perl doesn't recognize pack as being a function
which is understandable as I can't find reference to pack in 
TFM for ed, ex, sed, awk, perl, or C.   Anyone know how I might be able to
work around this little bug and get this to work.. Remember, this works on
some machine somewhere...  Any help would be appreciated.

	ian
--
-=Runaway Daemon=-



More information about the Comp.unix.questions mailing list