develooper Front page | perl.perl6.users | Postings from February 2019

Fastest way to convert from a Buf to a Str?

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
February 3, 2019 03:23
Subject:
Fastest way to convert from a Buf to a Str?
Message ID:
de19c3c9-f24f-6f7a-a23e-480e1a7d9629@zoho.com
Hi All,

I need to read a file into a buffer (NO CONVERSIONS!)
and then convert it to a string (again with no
conversions).

I have been doing this:

    for ( @$BinaryFile ) -> $Char { $StrFile ~= chr($Char); }

But it takes a bit of time.  What is the fastest way to do this?

I guess there is not a way to create/declare a variable that is
both Buf and Str at the same time?  That would mean I did not
have to convert anything.  I use to get away with this under
Module 2 all the time.

$ p6 'my $B = Buf.new(0x66, 0x66, 0x77); $B.Str ~= "z";'
Cannot use a Buf as a string, but you called the Str method on it
   in block <unit> at -e line 1

$ p6 'my $B = Buf.new(0x66, 0x66, 0x77); Str($B) ~= "z";'
Cannot use a Buf as a string, but you called the Str method on it
   in block <unit> at -e line 1


Many thanks,
-T

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A computer without Microsoft is like
a chocolate cake without the mustard
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About