a very simplistic example of a perl module

Discussion in 'Perl Misc' started by BH, Feb 26, 2008.

  1. BH

    BH Guest

    Hi,

    I would like to move some subroutines into a module, perlmod and other
    tutorials online seem to provide too much detail. Can someone
    demonstrate with a simple Module.pm which only have one subroutine and
    how this module can be used please?

    Regards,

    BH
    BH, Feb 26, 2008
    #1
    1. Advertising

  2. BH

    Guest

    BH <> wrote:
    > Hi,
    >
    > I would like to move some subroutines into a module, perlmod and other
    > tutorials online seem to provide too much detail. Can someone
    > demonstrate with a simple Module.pm which only have one subroutine and
    > how this module can be used please?
    >
    > Regards,
    >
    > BH


    Sure. But without without knowing some of the details (like package
    namespaces, at least) you miss most of the benefit to be had from using
    modules in the first place.


    $ cat Foo.pm
    sub foobar {
    return "This is the return value";
    };
    1;
    __END__

    $ cat foo.pl
    use strict;
    use warnings;
    use Foo;
    print foobar();
    __END__

    $ perl -l foo.pl
    This is the return value

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
    , Feb 26, 2008
    #2
    1. Advertising

  3. BH

    BH Guest

    Thanks.

    Can you add to the simple example another subroutine not to be
    exported, as well as 2 variables, one to exported and one not to be?

    Regards,

    BH

    On Feb 26, 7:18 pm, wrote:
    > BH <> wrote:
    > > Hi,

    >
    > > I would like to move some subroutines into a module, perlmod and other
    > > tutorials online seem to provide too much detail. Can someone
    > > demonstrate with a simple Module.pm which only have one subroutine and
    > > how this module can be used please?

    >
    > > Regards,

    >
    > > BH

    >
    > Sure.  But without without knowing some of the details (like package
    > namespaces, at least) you miss most of the benefit to be had from using
    > modules in the first place.
    >
    > $ cat Foo.pm
    > sub foobar {
    >   return "This is the return value";};
    >
    > 1;
    > __END__
    >
    > $ cat foo.pl
    > use strict;
    > use warnings;
    > use Foo;
    > print foobar();
    > __END__
    >
    > $ perl -l foo.pl
    > This is the return value
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > The costs of publication of this article were defrayed in part by the
    > payment of page charges. This article must therefore be hereby marked
    > advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    > this fact.
    BH, Feb 26, 2008
    #3
  4. BH

    Guest

    BH <> wrote:
    > Thanks.
    >
    > Can you add to the simple example another subroutine not to be
    > exported,


    No. Exporting is one of those details you didn't want to bother with.
    If you now want to bother with it, then go back to reading the docs
    you gave up on. I'm going to read them to you.

    > as well as 2 variables, one to exported and one not to be?


    Who will receive credit for your homework, me or you?


    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
    , Feb 26, 2008
    #4
  5. BH

    BH Guest

    Interesting! It's interesting someone actually thinks that any typical
    school/university will teach Perl as a subject? ;)

    On Feb 26, 7:51 pm, wrote:
    > BH <> wrote:
    > > Thanks.

    >
    > > Can you add to the simple example another subroutine not to be
    > > exported,

    >
    > No. Exporting is one of those details you didn't want to bother with.
    > If you now want to bother with it, then go back to reading the docs
    > you gave up on. I'm going to read them to you.
    >
    > > as well as 2 variables, one to exported and one not to be?

    >
    > Who will receive credit for your homework, me or you?
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > The costs of publication of this article were defrayed in part by the
    > payment of page charges. This article must therefore be hereby marked
    > advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    > this fact.
    BH, Feb 27, 2008
    #5
  6. [ If you don't want to continue to look silly, then do not top-post.
    Text rearranged into actual chronological order.
    ]

    BH <> wrote:
    > On Feb 26, 7:51 pm, wrote:



    >> Who will receive credit for your homework, me or you?
    >>

    > Interesting! It's interesting someone actually thinks that any typical
    > school/university will teach Perl as a subject? ;)



    I don't "think" it is taught, I "know" it is.

    I have taught a for-credit Perl class at a typical university.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Feb 28, 2008
    #6
  7. BH

    Uri Guttman Guest

    >>>>> "TJM" == Tad J McClellan <> writes:

    TJM> [ If you don't want to continue to look silly, then do not top-post.
    TJM> Text rearranged into actual chronological order.
    TJM> ]

    TJM> BH <> wrote:
    >> On Feb 26, 7:51 pm, wrote:



    >>> Who will receive credit for your homework, me or you?
    >>>

    >> Interesting! It's interesting someone actually thinks that any typical
    >> school/university will teach Perl as a subject? ;)



    TJM> I don't "think" it is taught, I "know" it is.

    TJM> I have taught a for-credit Perl class at a typical university.

    and there are certificate programs in perl at many colleges
    too. extensions schools (even harvard) teach perl. it isn't used much as
    the primary language for all compsci classes but it is taught in places.

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Architecture, Development, Training, Support, Code Review ------
    ----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
    Uri Guttman, Feb 28, 2008
    #7
  8. BH

    ccc31807 Guest

    On Feb 27, 3:54 pm, BH <> wrote:
    > Interesting! It's interesting someone actually thinks that any typical
    > school/university will teach Perl as a subject? ;)


    I've had five years of post-bat CS and SE, and have never been exposed
    to Perl in a University environment, but I ~have~ been exposed to
    COBOL, Scheme, Python, C, Java (lots), Microsoft languages (lots),
    shell scripts, assembly, X languages (XPath, XSLT, etc.), Mate,
    Erlang, and others I can't remember. No Perl, none at all.

    OTOH, I've taught at a college and taught the Perl course, which was
    taught as part of a state required curriculum. Yes, my state mandated
    that students learn Perl, but the curriculum was 20 years old when I
    taught, and that was five years ago, and it still IS the curriculum.

    I find it ironic that self-respecting academics won't touch Perl with
    a ten foot pole, yet teach it because of 20 year old state mandates.
    Don't get me wrong ... Perl is perhaps the most useful technology
    invented, but maybe that's why academics don't like it.

    CC
    ccc31807, Feb 28, 2008
    #8
  9. ccc31807 wrote:
    > Perl is perhaps the most useful technology
    > invented, but maybe that's why academics don't like it.


    No, Perl simply doesn't offer anything particularly new or unique or
    historically significant in the field of programming languages, and in
    some ways, it's just plain grotty. Learning Perl may be vocational
    training, but it's not education. (You don't get a degree in automotive
    engineering because you know how to replace the carburetor on a '57
    Chevy; you get it by learning metallurgy, and flame-front physics, and
    airflow mechanics.)

    --
    John W. Kennedy
    "The whole modern world has divided itself into Conservatives and
    Progressives. The business of Progressives is to go on making mistakes.
    The business of the Conservatives is to prevent the mistakes from being
    corrected."
    -- G. K. Chesterton
    John W. Kennedy, Feb 29, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. (Pete Cresswell)

    Frames: Simplistic Summary For The Noob?

    (Pete Cresswell), Oct 28, 2004, in forum: HTML
    Replies:
    20
    Views:
    789
    Dave Patton
    Oct 29, 2004
  2. John Doe
    Replies:
    3
    Views:
    390
    Sandeep
    Jul 9, 2003
  3. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    449
    Raymond Hettinger
    Jul 27, 2003
  4. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,589
    Merrill & Michele
    Oct 19, 2004
  5. Smithers

    Simplistic URL Rewriting

    Smithers, Nov 30, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    317
    Alexey Smirnov
    Nov 30, 2007
Loading...

Share This Page