Frage

The answer is probably obvious, but I'm wondering if there's a shorter way to write this:

if ($line =~ m/^REF:  /){
    $line =~ s/^REF:  //;
    # do something else
}
War es hilfreich?

Lösung

s/// returns the number of substitutions made. An equivalent of your code would be:

if ($line =~ s/^REF:  //) {
    # do something else
}

Andere Tipps

You mean?

if ($line =~ s/^REF:  //){
    print $line."\n";
}
else {
   print "Line not touched\n";
   }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top