Re: [LIP] Perl pack() question

Binand Sethumadhavan <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
Raj Mathur posted in linux-india-programmers:
> $packed = pack ( "CCCC" , @octets ) ;
> print ( unpack ( "H*" , $packed ) , "\n" ) ;
> 
> Remember, pack converts string->binary, unpack does the reverse
> (binary->string).

Thanks. Essentially I have to pack and then unpack (in a different
format), is it?

A silly follow-up question. The hex digits A-F your code generates are
in lower case. Any option to pack/unpack to let me have it in upper case?

Right now I am doing:

	my $q = unpack ("H*", pack ("CCCC", split (/\./, $ARGV[0])));
	$q =~ y/a-z/A-Z/;
	print "$q\n";

My ultimate aim is to do everything in one line and make the code look
as close to modem line noise as possible ;) $ARGV[0] is an IP address
in x.y.z.t format.

Binand

-- 
Hanlon's Razor: Never attribute to malice that which can be adequately
explained by stupidity.
Bruce's Razor: Never attribute to stupidity that which can be adequately
explained by Microsoft funding.


-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.