How do you use Perl::Critic with a short example?

Perl::Critic is a static code analysis tool for Perl. It helps enforce coding standards and best practices in Perl code. By analyzing your code, it provides suggestions for improvements, making your Perl scripts cleaner and more maintainable.

Here's a simple example of how to use Perl::Critic:

#!/usr/bin/perl use strict; use warnings; use Perl::Critic; my $critic = Perl::Critic->new(); my $source_code = 'sub foo { my $x = 1; }'; # Analyze the source code my @violations = $critic->critique($source_code); foreach my $violation (@violations) { print $violation->as_string(); }

perl perl critic code analysis coding standards perl best practices