Perl Modules and packages

N

nraju531

Hi,

I am new to perl scripting i want to know the were the perl modules and packages are in perl scripting language.


Regards,
Nagaraju
 
G

George Mpouras

You have to read the documentation butfFor a quick start create the
following three files at the same directory

test.pl


#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use summer qw/&fun1 &fun2 &sun1 $var/;

say fun1("hello");
say fun2("hello");
say sun1("hello");
say "var is $var";
$var = 153;
say summer::fun3("hello");
say $summer::foo;


summer.pm


package summer;
use spring;
use strict;
use warnings;
use Exporter;
our $VERSION = '0.1.1';
our @ISA = qw/Exporter spring/;
our %EXPORT_TAGS = ();
our @EXPORT = qw/&fun1 $var/;
our @EXPORT_OK = qw/&fun2 &sun1/;
our @EXPORT_FAIL = qw//;

our $var = 'Summer';
our $foo = 'Winter';

sub fun1 { return uc $_[0] }
sub fun2 { return "Hello World from package ". __PACKAGE__}
sub fun3 { return "\$var is $var" }

1; __END__ #<EMD OF MODULE>


spring.pm


BEGIN {
package spring;
use strict;
use warnings;
use Exporter;
our $VERSION = '0.1.1';
our @ISA = qw/Exporter/;
our %EXPORT_TAGS = ();
our @EXPORT = qw/&sun1 &sun2/; # exprort now
our @EXPORT_OK = qw//; # export on demand
@EXPORT_FAIL = qw//;

my $foo = 'hello';

sub sun1 { return "Hello World from package ". __PACKAGE__ }
sub sun2 { return "I am package spring" }

}1; __END__ #<EMD OF MODULE>



run test.pl and you are ready to go !
 
J

John Black

Not sure I understand your question. Perl comes with a large set of
"standard modules", which are installed in system libraries when you
install Perl. You can find out what they are by typing

perl -lE "print for @INC"

This sounded interesting. So I ran it on my system and got:

perl -lE "print for @INC"
Unrecognized switch: -E (-h will show valid options).

-ver reveals that v5.8.8 is installed.

John Black
 
M

Michael Vilain

John Black said:
This sounded interesting. So I ran it on my system and got:

perl -lE "print for @INC"
Unrecognized switch: -E (-h will show valid options).

-ver reveals that v5.8.8 is installed.

John Black

You're running something old or not on a linux/MacOS system:

dexlabs-ml[17]~ % perl -lE "print for @INC"
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level
/opt/local/lib/perl5/site_perl/5.12.4
/opt/local/lib/perl5/vendor_perl/5.12.4/darwin-thread-multi-2level
/opt/local/lib/perl5/vendor_perl/5.12.4
/opt/local/lib/perl5/5.12.4/darwin-thread-multi-2level
/opt/local/lib/perl5/5.12.4
/opt/local/lib/perl5/site_perl
/opt/local/lib/perl5/vendor_perl
..
dexlabs-ml[18]~ % perl --version

This is perl 5, version 12, subversion 4 (v5.12.4) built for
darwin-thread-multi-2level

Copyright 1987-2010, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to
the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
 
P

Peter J. Holzer

This sounded interesting. So I ran it on my system and got:

perl -lE "print for @INC"
Unrecognized switch: -E (-h will show valid options).

-ver reveals that v5.8.8 is installed.

The -E switch was introduced in v5.10. Use -e instead:

perl -le 'print for @INC'

(the difference between -e and -E is that -E enables all current
features, but this simple one-liner doesn't use any, so there is no
difference in this case)

I'm not sure whether that answers the OP's question, though.

hp
 
J

Jürgen Exner

Peter J. Holzer said:
perl -le 'print for @INC'

I'm not sure whether that answers the OP's question, though.

It does.
This command lists all locations, where the Perl interpreter (note the
lower case 'perl' in the OPs question) is looking for modules and
packages.
The real question is if this is what the OP meant to ask. But that is
something only he can answer.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top