Questions tagged [perl-module]

A Perl module is a reusable portion of Perl code.

In Perl, modules are vital to object-oriented design and can provide static variables referenced similarly to those in C++. The package model improves code organization, by allowing the coder to import functions from external files and 'bless' new object instances. Further, perl allows the directory structure holding modules to aid in the description of an object hierarchy. Perl module files traditionally have the extension '.pm'

see perlmod - perldoc.perl.org for more information.

1358 questions
13
votes
2 answers

Perl XS and Inline::C

What's the difference between using XS and the Inline::C module? This was mentioned by someone in this question and has made me curious.
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
13
votes
3 answers

How do you use a variable in lib Path?

I would like to use the $var variable in lib path. my $var = "/home/usr/bibfile;" use lib "$var/lib/"; However when I do this it throws an error. I'd like to use use lib "$var/lib/";instead of use lib "/home/usr/bibfile/lib/";. How can I assign a…
Sourcecode
  • 305
  • 4
  • 13
12
votes
4 answers

How do I tell from a module’s CPAN page whether it is in the core distribution?

For example, when going through the Time::HiRes documentation on search.cpan.org, is there some indication in the page itself the module is now part of Perl core distribution? I know I can usually find that out with some googling, but I'm trying to…
Sundar R
  • 13,776
  • 6
  • 49
  • 76
12
votes
4 answers

Should a Perl constructor return an undef or a "invalid" object?

Question: What is considered to be "Best practice" - and why - of handling errors in a constructor?. "Best Practice" can be a quote from Schwartz, or 50% of CPAN modules use it, etc...; but I'm happy with well reasoned opinion from anyone even if…
DVK
  • 126,886
  • 32
  • 213
  • 327
12
votes
6 answers

Which Perl module would you recommend for JSON manipulation?

As usual, I'm happy to deal with CPAN because it got all we need. As usual, I'm lost because there is plenty of stuff. I can find the core JSON one by myself, and feel enthusiastic by a JSON::Tiny other. My needs are very simple (parsing stuffs from…
smonff
  • 3,399
  • 3
  • 36
  • 46
12
votes
1 answer

List::MoreUtils mesh or 'zip' function

So this question is purely for learning purposes and curiosity, but can anyone explain how the function below works? sub mesh (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@) { my $max = -1; $max < $#$_ && ( $max = $#$_ )…
srchulo
  • 5,143
  • 4
  • 43
  • 72
11
votes
1 answer

Perl's Net::(SSH vs SSH2 vs OpenSSH) -- how should I compare them?

Looking to execute a perl script on a remote machine via a Perl script. Appears one option is to use system() function and create an ssh key so the password is not required. Which leads me to the focus of this question, the other option appears to…
blunders
  • 3,619
  • 10
  • 43
  • 65
11
votes
2 answers

Undefined subroutine called

I am trying to do simple module usage in Perl: Flame/Text.pm: package Flame::Text; sub words { … } 1; Flame/Query.pm: package Flame::Query; use Flame::Text qw(words); sub parse_query { words(shift); } parse_query 'hi'; 1; Why am I getting the…
user1804599
11
votes
1 answer

Is there any Perl module that can keep me from adding `or die` to anything that can fail?

I'm writing code that runs all sorts of external commands as well as various filesystem commands that can fail. Is there any module that can save me the trouble of adding or die to anything that can fail? I'd like to be able to wrap the following in…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
11
votes
7 answers

How can I update Perl on Windows without losing modules?

At work I'm using Perl 5.8.0 on Windows. When I first put Perl on, I went to CPAN, downloaded all the sources, made a few changes (in the .MAK file(?) to support threads, or things like that), and did nmake / nmake test / nmake install. Then, bit by…
piCookie
  • 9,640
  • 2
  • 19
  • 19
10
votes
2 answers

package variable scope in module subroutine

How do I change the value of a variable in the package used by a module so that subroutines in that module can use it? Here's my test case: testmodule.pm: package testmodule; use strict; use warnings; require Exporter; our ($VERSION, @ISA,…
user166560
10
votes
7 answers

Is there a way to replace an if-elsif-else in Perl with something better?

I want to build a bunch of Perl subrotines that all have the same template if elsif elsif else that takes a decision based on a factor variable. Here's an example of subroutine template: sub get_age{ my $factor=shift; if ($factor == 1 ){…
smith
  • 3,232
  • 26
  • 55
10
votes
1 answer

How long has a module been in Perl core?

The module I'm actually interested in is Sys::Hostname, but as a more general question, how can I tell how long a particular module has been a core module? I'm curious about this with regards to the Perl version.
Joel
  • 3,435
  • 2
  • 23
  • 33
10
votes
2 answers

How does this call to a subroutine in a Perl module work?

I recently saw some Perl code that confused me. I took out all of the extra parts to see how it was working, but I still don't understand why it works. Basically, I created this dummy "module" (TTT.pm): use strict; use warnings; package TTT; sub…
BrianH
  • 7,932
  • 10
  • 50
  • 71
10
votes
4 answers

Perl, how to determine if a variable value is a number?

Is there a unique method to determine if a variable value is a number, Since the values could be in scientific notation as well (for example, 5.814e-10)?
Gordon
  • 1,633
  • 3
  • 26
  • 45
1 2
3
90 91