Gunnar Hjalmarsson wrote:
> Rob Dixon wrote:
>> Noah wrote:
>>> Rob Dixon wrote:
>>>> Then I guess you are processing a file that originated on a Windows system?
>>>> Windows text files have a <CR><LF> sequence at the end of each record, 
>>>> whereas
>>>> Unix files have just <LF>. <CR> is control-M, which is why vim is showing 
>>>> ^M at
>>>> the end of the line.
>>>>
>>>> What you need to do it to remove all whitespace from the end of lines 
>>>> after you
>>>> read them (from both the template and the config files) like this.
>>>>
>>>>   @config_file_lines = <INPUT>;
>>>>   s/\s+$// foreach @config_file_lines;
>>>>
>>>> That will remove and CR or LF characters as well as spaces and tabs (and 
>>>> FFs
>>>> actually) so that there are no line terminators at all and the record 
>>>> contents
>>>> can be compared properly.
>>> okay the necessary line feed at the end of the line is disappearing.
>>> would it be better to something like:
>>>
>>> @config_file_lines = <INPUT>;
>>> s/\s+$/\n/ foreach @config_file_lines;
>> The newline is only necessary if you perform the substitution only on one 
>> set of
>>  records. If you also apply it to those from the template file as I said 
>> then it
>> will work fine.
> 
> I don't get it. The OP wants to compare lines. How would that work fine 
> if there are no lines to compare?

I'm talking about removing the line terminators. It looks like the OP is trying
to compare unchomped records from a Windows text file with the same from a Unix
text file. The comparison is failing because although the text is the same the
line terminators are different. It now looks like he's trimming trailing
whitespace from only the Windows files so they still don't match.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to