How to perform syntax check for Perl program
Answer:
Assume you have a Perl script test.pl, try run the command
perl -c test.pl
Syntax error will be displayed without running the code actually.
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How to perform syntax check for Perl program
Answer:
Assume you have a Perl script test.pl, try run the command
perl -c test.pl
Syntax error will be displayed without running the code actually.
How to sort a hash in Perl
Answer:
# %hash is the hash to sort
@keys = sort { criterion() } (keys %hash);
foreach $key (@keys) {
$value = $hash{$key};
# do something with $key, $value
}
How to pretty print my.cnf with a one-liner?
Answer:
A very cool command.
perl -ne 'm/^([^#][^\s=]+)\s*(=.*|)/ && printf("%-35s%s\n", $1, $2)' /etc/my.cnf
Reference: http://www.mysqlperformanceblog.com/2009/06/15/how-to-pretty-print-mycnf-with-a-one-liner/
How to check if a Perl module is already installed?
Answer:
For example, to check if the DBI module is installed or not, use
perl -e 'use DBI;'
You will see error if not installed.
Split a string into array in Perl
Answer:
To split a string into an array in Perl, follow the codes below
my $data = 'peter,mary,john';
my @values = split(',', $data);