unpack vs. split problem (really weird)

M

Mike Hunter

Hey everybody,

I'm having a weird problem. Check this out:

sub mth_inet_ntoa
{
my $stuff = shift;
$debug and print "mth_inet_ntoa_debug length \$stuff: ".(length $stuff)."\n";
my @o = split //, $stuff;
$debug and print "mth_inet_ntoa debug lengths ".
(length $o[0])." ".(length $o[1])." ".(length $o[2])." ".(length $o[3])."\n";
$debug and print "mth_inet_ntoa debug ".(join "", (unpack "b*", $stuff))."\n";
$debug and print "mth_inet_ntoa debug #".(join "", unpack "b*", $o[0]).
"#".(join "", unpack "b*", $o[1])."#".
(join "", unpack "b*", $o[2])."#".(join "", unpack "b*", $o[3])."#\n";
return "$o[0].$o[1].$o[2].$o[3]";
}

mth_inet_ntoa_debug length $stuff: 4
mth_inet_ntoa debug lengths 1 1 1 1
mth_inet_ntoa debug 00000001000001001010110000000000
mth_inet_ntoa debug #00000001#00000100#10101100#00000000#

Now, if I change from

split //, $stuff

to

unpack "CCCC", $stuff

I get these totally weirded-out results:

mth_inet_ntoa_debug length $stuff: 4
mth_inet_ntoa debug lengths 3 2 2 1
mth_inet_ntoa debug 00000001000001001010110000000000
mth_inet_ntoa debug #100011000100110000011100#1100110001001100#1010110011001100#00001100#

perl -V:

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=freebsd, osvers=4.8-release, archname=i386-freebsd
...

Shouldn't unpack "CCCC" work?

Mike
 
J

John W. Krahn

Mike said:
I'm having a weird problem. Check this out:

[snip]

mth_inet_ntoa_debug length $stuff: 4
mth_inet_ntoa debug lengths 1 1 1 1
mth_inet_ntoa debug 00000001000001001010110000000000
mth_inet_ntoa debug #00000001#00000100#10101100#00000000#

Now, if I change from

split //, $stuff

to

unpack "CCCC", $stuff

I get these totally weirded-out results:

mth_inet_ntoa_debug length $stuff: 4
mth_inet_ntoa debug lengths 3 2 2 1
mth_inet_ntoa debug 00000001000001001010110000000000
mth_inet_ntoa debug #100011000100110000011100#1100110001001100#1010110011001100#00001100#

[snip]

Shouldn't unpack "CCCC" work?

The equivalent of:

my @o = split //, $stuff

Is:

my @o = unpack 'a' x length $stuff, $stuff


The equivalent of:

my @o = unpack 'CCCC', $stuff

Is:

my @o = map ord, split //, $stuff



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top