[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] Perl binary -> hex



I've got a smal UDP server written in perl that receives data via UDP. 
This data is in binary format.  I need to convert that data to a string
that is a hex representation and then I need to be able to convert back
to the original data.  How can I do this?

Here is some code that I have:

while (1) {
        my $data =undef ;
        ($hispaddr = recv(SOCKET, $data, 1024, 0))        || die "recv:
$!";
        ($port, $hisiaddr) = sockaddr_in($hispaddr);
        do {
                use bytes;
                print length($data)."\n";
        }
}


I've tried using a for loop to walk the $data byte by byte but that does
not seem to work.