Perl equivalent of python array.array(typecode, ..)?

Edit You need to clarify what you're saying. On my python (2.7.2), this is wrong: FILE. Write(data) because data needs to be a string.

I think what you mean to say instead is: data. Tofile(FILE) Anyway, is this what you want? Print pack("s*", unpack("C*", "abcd")) # piped through xxd => 0000000: 6100 6200 6300 6400 a.b.c.

D Have a look through perldoc -f pack for the correct template string to use. Since you don't have access to W (unsigned wchar), i'm using C (unsigned char) s is a signed short (corresponding to python's h ) edit There are no typed arrays in Perl ord returns the numeric value of the first character of its argument Assuming this is what you want, just map the list resulting from splitting $packet on each character to data transforming each element with ord (the argument $ is implicitly given. ) my @data = map { ord } split //, $packet; # or my @data = unpack 'W*', $packet Optionally, using a range different from the actual lower and upper bounds on $packet : (split //, $packet)$start .. $end; # or split //, substr $packet, $start, $end # ysth's version.

Edit You need to clarify what you're saying. On my python (2.7.2), this is wrong: FILE. Write(data) because data needs to be a string.

I think what you mean to say instead is: data. Tofile(FILE) Anyway, is this what you want? Print pack("s*", unpack("C*", "abcd")) # piped through xxd => 0000000: 6100 6200 6300 6400 a.b.c.d.

Have a look through perldoc -f pack for the correct template string to use. Since you don't have access to W (unsigned wchar), i'm using C (unsigned char). S is a signed short (corresponding to python's h.) /edit There are no typed arrays in Perl.

Ord returns the numeric value of the first character of its argument. Assuming this is what you want, just map the list resulting from splitting $packet on each character to @data, transforming each element with ord (the argument $_ is implicitly given.) my @data = map { ord } split //, $packet; # or my @data = unpack 'W*', $packet; Optionally, using a range different from the actual lower and upper bounds on $packet: (split //, $packet)$start .. $end; # or split //, substr $packet, $start, $end # ysth's version.

Or split(//, substr($packet, $start, $end)) – ysth Jul 4 at 1:33 @Pedro Silva, FILE. Write(data) is working in my tests (implicit conversion to string? ).

Anyway the pack/unpack suggestion is promising (as tested for dummy data). I'll test it on actuall data and will update here. As for 'W' option I believe I have it in my version of perl back in home.

Will try that as well. Thanks! – LovelyVirus Jul 4 at 15:26 Thanks for the hints Pedro.

With pack/unpack one can mimic array. Array(typecode, ...) functionality. As for FILE.

Write(array), it appears that array.tostring() is called implicitly... – LovelyVirus Jul 5 at 1:18.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions