Neatest way to remove linebreaks in Perl

前端 未结 7 1179
孤街浪徒
孤街浪徒 2020-12-23 09:16

I\'m maintaining a script that can get its input from various sources, and works on it per line. Depending on the actual source used, linebreaks might be Unix-style, Windows

7条回答
  •  别那么骄傲
    2020-12-23 09:39

    Whenever I go through input and want to remove or replace characters I run it through little subroutines like this one.

    sub clean {
    
        my $text = shift;
    
        $text =~ s/\n//g;
        $text =~ s/\r//g;
    
        return $text;
    }
    

    It may not be fancy but this method has been working flawless for me for years.

提交回复
热议问题