|
Posted by monk on March 3, 2008, 8:25 pm
Please log in for more thread options > In article
>
>
>
> > Thanks for the tip 'od -c <filename>'
>
> > I uncovered an extra character was being added somehow when slurping
> > the config file.
> > I added one little line to my code and now it works like a charm.
>
> > foreach (@directories_to_clean){
> > chomp;
>
> > chop; # one extra line that solved my problem.
>
> > print "$_\n";
>
> > #and everything else is the same
>
> > }
>
> That is not a good, long-term solution. It is not likely that slurping
> the file is adding extra characters. It is more likely that the file
> does not have the proper line endings for your system. As soon as
> somebody edits your file with the proper editor, it may remove the
> extra characters and your program will no longer work.
>
> You should determine exactly what the extra characters are and remove
> them. chop will remove the last character of your string, regardless of
> what it is.
>
> In your original program, which you do not show, you have already used
> chomp on the lines read from your file, and the chomp shown above is a
> no-op. chomp will remove the expected line-ending character or
> characters from a string. If they are not found, chomp does nothing.
>
> Use the substitute operator or the tr operator to remove only those
> characters that do not belong:
>
> s/[\r\n]+//;
> tr/\r\n/d;
>
> --
> Jim Gibson
Jim, you're absolutely right.
So yeah, using <od -c filename> I identified the extra characters that
were added and then used regular substitution. This is a much more
efficient approach. Now I'm just removing only the ones I need. Not
just whatever was there.
thanks,
|