On Mon, Feb 25, 2013 at 2:38 PM, Brandon McCaig <bamcc...@gmail.com> wrote:
> On Sun, Feb 24, 2013 at 11:17:40PM -0300, Brian Fraser wrote:
>> my $over = '';
>> while ( sysread( $fh, $over, 8192, length($over) ) ) {
>>     while ( $over =~ /\R/ ) {
>>       my $line = encode('UTF-8', substr($over, 0, $+[0], ''));
>
> I think you meant decode. :) Decode input, encode output. The
> internal storage that Perl uses isn't relevant. Apologies if I'm
> wrong. I am tired. >:)
>

You're absolutely right! I should've actually tested the code before
sending it : ) There's other errors there too; a missing $!, and it's
not checking for leftover \n at the start of each line. Sorry about
that!

> I would probably suggest moving the substr call onto a separate
> line because it's already obscure that it has side effects
> without explicitly assigning or referencing. I had to look it
> over several times and have faith in you before I figured out how
> it is meant to work.
>

I entirely agree for production code, but I felt that here it would've
just clouded the intent of the code; If someone didn't know what four
arg substr/encodings/@+ are, they could start a new thread.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to