Re: [LIP] Perl pack() question

Raj Mathur <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
>>>>> "Binand" == Binand Sethumadhavan <[email protected]> writes:

    Binand> This ought to be simple. I have this snippet: my @octets =
    Binand> split (/\./, $ip); foreach $o (@octets) { printf "%02X",
    Binand> $o; }

    Binand> (ie, take an IP address and get it as a string of four Hex
    Binand> numbers. This is to create PXE installation config files -
    Binand> lots of them).

    Binand> Is there a way to rewrite the stuff in the foreach loop
    Binand> using pack()? I am sort of unfamiliar with the pack() :)

$packed = pack ( "CCCC" , @octets ) ;
print ( unpack ( "H*" , $packed ) , "\n" ) ;

Remember, pack converts string->binary, unpack does the reverse
(binary->string).

Regards,

-- 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


-------------------------------------------------------
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.