Re: using a library

Discussion in 'Perl Misc' started by Janek Schleicher, Mar 1, 2014.

  1. Am 28.02.2014 19:57, schrieb Marek Novotny:
    > use strict;
    > use warnings;
    >
    > require 'obj13-lib.pl';



    As usual, I won't answer to your original question.

    Right now, I just want to emphasize the convention when working with
    libraries.

    In Perl, we usually call them '*.pm',
    that is a pretty unique file ending,
    that makes it clear, there is a Perl Module, also called a library.
    So, the canonical name for your library would be 'Obj13.pm' [usually
    modules are written uppercase].

    Usually we would use the library via 'use',
    so we'd write

    use Obj13;

    instead of require 'obj13-lib.pl';

    Technical, use XYZ is the same as
    BEGIN { require 'XYZ' }
    so there is not much difference.
    (BEGIN { ... } means it is run first, not at runtime).

    In the long run, it is better to get a problem signaled at compile time
    than at run time, as then there might be strange errors.
    Usually, we only use require '...' when we want to load a library
    dynamic (e.g. we'd prefer to work with a compiled C library, but if not
    availably we take the pure Perl pendant)


    I hope that does not confuse you more,
    I just wanted to hint you to the usual conventions,
    as it will make your programming life easier long term.



    Greetings,
    Janek
    Janek Schleicher, Mar 1, 2014
    #1
    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. Mythran
    Replies:
    0
    Views:
    2,416
    Mythran
    Aug 24, 2004
  2. Alan Ferrandiz [MCT]
    Replies:
    0
    Views:
    443
    Alan Ferrandiz [MCT]
    Sep 11, 2004
  3. Sweep

    Library in library...

    Sweep, Dec 8, 2003, in forum: C++
    Replies:
    1
    Views:
    382
    Jack Klein
    Dec 9, 2003
  4. Replies:
    6
    Views:
    827
    red floyd
    May 10, 2005
  5. David Soukal

    library using library?

    David Soukal, May 14, 2004, in forum: C Programming
    Replies:
    10
    Views:
    618
    Brian Gough
    May 17, 2004
Loading...

Share This Page