The ;
is used as a statement delimiter, so placing multiple ;
at the end of a statement is fine as it just adds empty statements.
I came across this code which has multiple ;
at the end but deleting them causing errors:
$line =~s;[.,]$;;;
should be same as
$line =~s;[.,;]$;
but it is not. What's going on?
Semicolons are required after all simple statements in Perl (except at the end of a block). Newline is not a statement delimiter.
every statement in Perl must end with a semicolon(;).
in the snippet provided by you a ;
is used as a delimiter for a search-n-replace regular expression.
$line =~s;[.,]$;;;
is equivalent to
$line =~ s/[.,]$//;
In your code only the last ;
is the statement delimiter. The others are regex delimiters which the substitution operator takes. A better way to write this is:
$line =~s/[.,]$//;
Since you must have the statement delimiter and regex delimiters in your statement, you can't drop any of the trailing ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With