DEV Community

Discussion on: What is X in Perl?

Collapse
 
matthewpersico profile image
Matthew O. Persico

; is mandatory (with few exceptions but please forget)

A semicolon ends a statement. It's what allows multi-line statements to appear without annoying backslashes. The only place I remember that you don't need one is at the end of a block:

for (...) {
statement1;
statement2;
statement3
}

However, you frequently see this code:
funccall (
arg1,
arg2,
arg3,
);

Notice the comma at the end of arg3? It's there so when you add arg4, It Just Works. So if you are willing to do that, put the semicolon after statement3 so that when you add statement4, It Just Works.

Don't be afraid of punctuation. We've been using it for hundreds of years and it has made reading so much easier; it does the same in programing.