I am not too clear on how pack works in perl5.

Is there a work around in perl6 to achieve the same result, viz., not using pack?

Richard

On 02/14/2011 02:41 AM, Carl Mäsak wrote:
Richard (>):
I came across the idiom

print "P4\n$w $h\n";
for my $y (0..$h-1) {
    print pack 'B*', pack 'C*', map dot($_, $y), 0..$w-1;
}

in a perl5 program for outputting dots in a graphical format. dot() produces
a 0 or -1.

I found the 'pack' function in perl6, but it does not seem to work the same.
Two differences that I can think of:

* The pack function in Rakudo is not fully implemented. For the cases
"B*" and "C*", I can definitely imagine that it doesn't work yet.
Patches are welcome. I also plan to find some time to work more on it
myself.

* The fundamental difference in Perl 6 would be that a call to 'pack'
would result in a Buf, not a string as in Perl 5. (This is because
Perl 6 makes a clear separation between sequences of bits/bytes, and
strings of characters. 'pack' deals in the former.) It's not immediate
to me that a Buf could be output without first having been converted
to a Str. A conversion may or may not be necessary for it to work.

// Carl

Reply via email to