Skip Menu |

This queue is for tickets about the String-Util CPAN distribution.

Report information
The Basics
Id: 78095
Status: rejected
Priority: 0/
Queue: String-Util

People
Owner: Nobody in particular
Requestors: TEX [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Support removing comments and empty lines in trim
Please consider applying the attached patch which adds to options to trim: comments and lines. Both are false by default. It set to a true value 'comments' will remove anything following a hash tag (#). 'lines', if set, will remove any empty lines.
Subject: comment-lines.patch
--- Util.pm.orig 2012-06-28 16:06:58.000000000 +0200 +++ Util.pm 2012-06-28 16:13:15.000000000 +0200 @@ -208,12 +208,23 @@ $var = trim($var, right=>0); +trim also accepts two other arguments, 'comments' and 'lines', both +of which are false by default. + +Setting 'comments' to a true value will remove anything following +a hash comment (#). Setting 'lines' to a true value will remove any lines +before retruning the result. + =cut sub trim { my ($val, %opts) = @_; if (defined $val) { + # remove trailing comments + if ( defined($opts{'comments'}) ? $opts{'comments'} : 0 ) + { $val =~ s/#.*//g; } + # trim left if ( defined($opts{'left'}) ? $opts{'left'} : 1 ) { $val =~ s|^\s+||s } @@ -221,6 +232,10 @@ # trim right if ( defined($opts{'right'}) ? $opts{'left'} : 1 ) { $val =~ s|\s+$||s } + + # remove empty lines + if ( defined($opts{'lines'}) ? $opts{'lines'} : 0 ) + { $val =~ s/^$//gms; } }; return $val;
Thanks for the idea, but I'm going to decline this one. There are too many different types of comments in different languages to set just one type of comment remover. For removing empty lines, that might be a nice new sub for the module, but not for trim which, as the name implies, is for removing leading and trailing whitespace.