Question

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
}
Was it helpful?

Solution

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

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

OTHER TIPS

You mean?

if ($line =~ s/^REF:  //){
    print $line."\n";
}
else {
   print "Line not touched\n";
   }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top