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.
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 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);
List all the installed Perl modules
Answer:
To list all the installed Perl modules in the system, use the following command.
# perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'
/usr/local/lib/perl/5.10.0/IO/Tty.pm
/usr/local/lib/perl/5.10.0/IO/Tty/Constant.pm
/usr/local/lib/perl/5.10.0/Params/ValidatePP.pm
/usr/local/lib/perl/5.10.0/Params/Validate.pm
...
Remove newline character from the end of a string in Perl
Answer:
chomp() is useful when reading data from a file or from a user - it remove remove any newline character from the end of a string.
E.g.
while (my $text = ) {
chomp($text);
print "You entered '$text'\n"; # newline from input is removed
}
Replace a string using regular expressions in Perl
Answer:
The following code demo how to replace a string in Perl,
my $s = 'love foobar';
$s =~ s/love/hate/g;
print $s;