tags:

views:

66

answers:

1

I couldn't understand what exactly "W" do.

my $x = "this is my string";

print unpack("W",substr($x,0,1));

Prints: 116

my $x = "this is my string";

print unpack("W",$x);

Still Prints: 116

+6  A: 

From perldoc: W An unsigned char value (can be greater than 255).

Both of your examples return the same thing because your unpack argument "W" only consumes one character. Try "W*" instead.

Eric Strom
Yeah. You are right but why 116? ASCII value of "t" aint that.
Shubham
`ord 't' == 116` and `The ASCII code for capital T is 84 and for lowercase t is 116` - http://en.wikipedia.org/wiki/T
Eric Strom
Shubham: `man ascii` works on any unix system. It's the fastest way of checking hex/octal/decimal values of ascii characters.
Ether