EverythingRightPlace
EverythingRightPlace

Reputation: 1197

General check of missing semicolon

As a Perl beginner I am sometimes getting compilation errors and have to search a lot to find it. In the end it is just a missing semicolon at the end of a line. Some syntax errors with missing semicolon are checked by Perl but not in general. Is there a way to get this check?

edit:

I know about Perl::Critic but can't use it atm. And I don't know if it checks for missing semicolon in general.

Upvotes: 1

Views: 984

Answers (3)

AlfredoVR
AlfredoVR

Reputation: 4287

use diagnostics; usually gives you a nice hint, same as use warnings;. Try to keep a consistent coding style, check perlstyle. Also you can use Perl::Critic online.

Also as general advice learn how to use packages and modules, try to group code into subs and study the syntax of arrays, lists and hashes. A common mistake is forgetting the ; after an anonymous hashref assignment:

my $hashref = { a => 5, b => 10};

Upvotes: 1

daxim
daxim

Reputation: 39158

The syntax check is perl -c, but that's no different than attempting to run the program outright. Due to its flexible/undecidable syntax, one cannot generally do what you want. That's the downside of comfort and expressiveness.

Upgrade to the latest stable Perl, the parser's error messages got better/more exact over the last years and will correctly recognise many circumstances of a missing semicolon.

Rule of thumb that works for many parsers/other languages: if the error makes no sense, look a couple of lines before.

Upvotes: 1

Kyle Strand
Kyle Strand

Reputation: 16499

Because semicolons actually mean something in Perl and aren't just there for decoration, it's not possible for any tool (even the Perl interpreter itself) to know in every case whether you actually meant to leave off the semi-colon or not. Thus, there's no general-case answer to your question; you'll just need to go through your code and make sure it's correct.

As mentioned in my comments, there are various tricks you can try with your editor to expedite the process of finding potentially-incorrect lines; you must, however, either examine and fix these by hand or risk introducing new problems.

Upvotes: 2

Related Questions