in reply to How to trim a line from leading and trailing blanks without using regex or non-standard modules

>$line =~ s/^\s+|\s+$//g which clearly is an abuse of regex.

Why do you say that?

>trim function which BTW was present in Perl 6

You say this like it's a good thing. I bet there is also one in PHP.

  • Comment on Re: How to trim a line from leading and trailing blanks without using regex or non-standard modules
  • Download Code

Replies are listed 'Best First'.
Re^2: How to trim a line from leading and trailing blanks without using regex or non-standard modules
by karlgoethebier (Abbot) on Aug 14, 2020 at 12:34 UTC

    You won

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

      easily re-implemented in Perl. It seems ...

      DB<33> sub trim { $_[1] //= qr/\s/; $_[0] =~ s/^[$_[1]]+|[$_[1]]+$// +g } DB<34> $a = $b = " \n . aaa . \n " DB<35> trim $a DB<36> trim $b, " " DB<37> x $a,$b 0 '. aaa .' 1 ' . aaa . ' DB<38>

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        I was pretty sure that you would answer and provide a solution 😎 Best regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

        perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help