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;