Perl Modules and packages

Discussion in 'Perl Misc' started by nraju531, Dec 14, 2013.

  1. nraju531

    nraju531 Guest


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

    nraju531, Dec 14, 2013
    1. Advertisements

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

    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;

    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>

    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 and you are ready to go !
    George Mpouras, Dec 14, 2013
    1. Advertisements

  3. nraju531

    John Black Guest

    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
    John Black, Dec 16, 2013
  4. You're running something old or not on a linux/MacOS system:

    dexlabs-ml[17]~ % perl -lE "print for @INC"
    dexlabs-ml[18]~ % perl --version

    This is perl 5, version 12, subversion 4 (v5.12.4) built for

    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
    Internet, point your browser at, the Perl Home Page.
    Michael Vilain, Dec 16, 2013
  5. 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.

    Peter J. Holzer, Dec 16, 2013
  6. 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
    The real question is if this is what the OP meant to ask. But that is
    something only he can answer.

    Jürgen Exner, Dec 16, 2013
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.