# New Ticket Created by Ron Schmidt # Please include the string: [perl #114614] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=114614 >
The eq and similar string operators are allowed for comparing (same bit size?) buffers as documented in S32 - http://perlcabal.org/syn/S32/Containers.html#Buf_Operators. This is useful for finding things in Bufs like CRLF sequences in http headers. I tried comparing something like Buf.new(13, 10) eq $tcp_recv_buff[ $i, $i +1] and it failed with the above error message because I am trying to compare a buf to parcel. It was later shown by TimToady++ that for the $tcp_recv_buff I should have been using the subbuf method. The error message "Cannot use a Buf as a string, but you called the Str method on it" seems to confusingly imply that Buf does not use the eq operator when in the right context it does. Even if one compared Buf.new(65, 66) eq 'AB' a better error message might tell the user something like "Can only do string equality between Bufs or Str converted/decoded Buf and Str". Buf.new(65, 66).decode('utf-8') eq 'AB' works but Buf.new(65,66) eq 'AB'.encode('utf-8') works too and might be the needed answer if, for example, you are not sure whether the Buf properly decodes to 'utf-8' or not. There is a similar issue with the ~ operator. For example: perl6 -e 'my $x = Buf.new(65); $x ~= Buf.new(66); say $x.decode("ascii")' AB perl6 -e 'my $x = Buf.new(65); $x ~= "B"; say $x.decode("ascii")' Cannot use a Buf as a string, but you called the Str method on it There is no problem with Rakudo not appending a string to Buf but again the error message could be more informative and explain that ~ works on Bufs just not Bufs combineed with Strings. Ron
