Re: [LIP] Perl pack() question
Raj Mathur <[email protected]>
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 >>>>> "Binand" == Binand Sethumadhavan <[email protected]> writes: Binand> 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). Binand> Thanks. Essentially I have to pack and then unpack (in a Binand> different format), is it? Binand> A silly follow-up question. The hex digits A-F your code Binand> generates are in lower case. Any option to pack/unpack to Binand> let me have it in upper case? Binand> Right now I am doing: Binand> my $q = unpack ("H*", pack ("CCCC", split (/\./, Binand> $ARGV[0]))); $q =~ y/a-z/A-Z/; print "$q\n"; Will print ( uc ( unpack ("H*", pack ("CCCC", split (/\./, $ARGV[0]))) ) , "\n" ) ; do the trick? TIMTOWTDI, but TIOOWTDI (There Is Only One Way To Do It): do { "perl" } || die "$!" Binand> My ultimate aim is to do everything in one line and make Binand> the code look as close to modem line noise as possible ;) Binand> $ARGV[0] is an IP address in x.y.z.t format. Perl, the only language that looks the same before and after PGP encryption :) - -- Raju - -- Raj Mathur [email protected] http://kandalaya.org/ GPG: 78D4 FC67 367F 40E2 0DD5 0FEF C968 D0EF CC68 D17F It is the mind that moves -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/> iD8DBQFA0ToyyWjQ78xo0X8RAsMlAKCWKDSoWo/yyC9d2hAatnRk9jAk0gCZAU13 UwK4EUkDM4dr+pVbRD3ZrIY= =9e7o -----END PGP SIGNATURE----- ------------------------------------------------------- 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