Explorar el Código

perl: Use length instead of /^$/ to test for an empty string

Addresses RegularExpressions::ProhibitFixedStringMatches.

Warned-by: perlcritic
Guillem Jover hace 12 años
padre
commit
24df99399b

+ 2 - 2
dselect/methods/ftp/install

@@ -85,13 +85,13 @@ sub getblk {
     my %flds;
     my $fld;
     while (<$fh>) {
-	if ( ! /^$/ ) {
+	if (length != 0) {
 	    FLDLOOP: while (1) {
 		if ( /^(\S+):\s*(.*)\s*$/ ) {
 		    $fld = lc($1);
 		    $flds{$fld} = $2;
 		    while (<$fh>) {
-			if ( /^$/ ) {
+			if (length == 0) {
 			    return %flds;
 			} elsif ( /^(\s.*)$/ ) {
 			    $flds{$fld} = $flds{$fld} . "\n" . $1;

+ 2 - 1
scripts/Dpkg/Conf.pm

@@ -102,7 +102,8 @@ sub parse {
 	s/^\s+//; s/\s+$//;   # Strip leading/trailing spaces
 	s/\s+=\s+/=/;         # Remove spaces around the first =
 	s/\s+/=/ unless m/=/; # First spaces becomes = if no =
-	next if /^#/ or /^$/; # Skip empty lines and comments
+	# Skip empty lines and comments
+	next if /^#/ or length == 0;
 	if (/^-[^-]/ and not $self->{allow_short}) {
 	    warning(_g('short option not allowed in %s, line %d'), $desc, $.);
 	    next;

+ 3 - 3
scripts/Dpkg/Control/HashCore.pm

@@ -197,7 +197,7 @@ sub parse {
 
     while (<$fh>) {
 	s/\s*\n$//;
-	next if (m/^$/ and $paraborder);
+	next if length == 0 and $paraborder;
 	next if (m/^#/);
 	$paraborder = 0;
 	if (m/^(\S+?)\s*:\s*(.*)$/) {
@@ -232,7 +232,7 @@ sub parse {
 	    } else {
 		$self->parse_error($desc, _g('OpenPGP signature not allowed here'));
 	    }
-	} elsif (m/^$/ || ($expect_pgp_sig && m/^-----BEGIN PGP SIGNATURE-----$/)) {
+	} elsif (length == 0 || ($expect_pgp_sig && m/^-----BEGIN PGP SIGNATURE-----$/)) {
 	    if ($expect_pgp_sig) {
 		# Skip empty lines
 		$_ = <$fh> while defined && m/^\s*$/;
@@ -356,7 +356,7 @@ sub output {
 	    $kv .= "\n";
 	    foreach (@lines) {
 		s/\s+$//;
-		if (/^$/ or /^\.+$/) {
+		if (length == 0 or /^\.+$/) {
 		    $kv .= " .$_\n";
 		} else {
 		    $kv .= " $_\n";

+ 1 - 1
scripts/Dpkg/Source/Package/V2.pm

@@ -711,7 +711,7 @@ sub load_allowed_binaries {
             or syserr(_g('cannot read %s'), $incbin_file);
         while (<$incbin_fh>) {
             chomp; s/^\s*//; s/\s*$//;
-            next if /^#/ or /^$/;
+            next if /^#/ or length == 0;
             $self->{allowed_binaries}{$_} = 1;
         }
         close($incbin_fh);

+ 8 - 4
scripts/Dpkg/Source/Patch.pm

@@ -515,10 +515,14 @@ sub analyze {
 		}
 		next if /^\\ /;
 		# Check stats
-		if    (/^ / || /^$/)  { --$olines; --$nlines; }
-		elsif (/^-/)  { --$olines; }
-		elsif (/^\+/) { --$nlines; }
-		else {
+		if (/^ / or length == 0) {
+		    --$olines;
+		    --$nlines;
+		} elsif (/^-/) {
+		    --$olines;
+		} elsif (/^\+/) {
+		    --$nlines;
+		} else {
 		    error(_g("expected [ +-] at start of line %d of diff `%s'"),
 		          $., $diff);
 		}