SOLVED (sort of): perl script prints parts of strings in the wrong order

Olivier Olivier.Nicole at cs.ait.ac.th
Tue Aug 7 05:56:21 UTC 2018


"M. Fioretti" <mfioretti at nexaima.net> writes:

> as usual, I stumped in the solution one second after posting to the 
> list, but I
> can't say I completely understand it, so any comment is welcome.
>
> I piped the output of the script through "od -c", and saw lots of \r 
> characters
> right in the places where pieces of strings were "swapped".
>
> So I changed this:
>
> chomp;
>
> to this:
>
> chomp;
> s/\r//g;
>
> and now everything works as intended. Problem is, *why* did I have to do 
> this?
> I thought the "chomp" command in Perl also strips those \r characters 
> out, and
> I am pretty sure it did, earlier.

According to perl documentation, chomp removes the eding of a line that
corresponds to teh current value of $/ so it really depends what you set
into $/

Bests,

livier

>
> Thanks,
> Marco
>
>
> On 2018-08-07 07:28, M. Fioretti wrote:
>> hello,
>> 
>> I am trying to reuse an old perl script I wrote years ago, on an
>> Ubuntu 16.-04LTS x86_64 box.
>> It behaves in a very odd way now, and I cannot figure out if it is the
>> code that is not
>> compatible with current versions of Perl, or if there is something
>> VERY strange happening
>> between the script, and the terminal it runs in.
>> 
>> The part of the script that works badly is this:
>> 
>> while (<INPUTFILE>) {
>>     chomp;
>>     my $LINE = $_;
>>     many lines that "clean up" $LINE, removing certain substrings 
>> etc...
>> 
>>     @F = split /:/, $LINE;
>>     print "CURL:==> $F[0] ++ $CURLRES{$F[0]} ;;\n";
>> }
>> 
>> when I run it, SOME of the printed lines (say 1 every 30) have the
>> expected format:
>> 
>> CURL:==> string_a ++ string_b ;;
>> 
>> but all the others are like this:
>> 
>> 
>>  ;;L:==> string_c ++ string_d ;;
>> 
>> that is, the three initial "CUR" characters are replaced by " ;;"
>> 
>> It's as if something had pasted the last three characters over the
>> first three ones.
>> 
>> I have no idea what is going wrong, and why. Any help is appreciated,
>> 
>> TIA,
>> 
>> Marco
>
> -- 
> http://mfioretti.com

-- 



More information about the ubuntu-users mailing list