carlriz has asked for the wisdom of the Perl Monks concerning the following question:

What exactly is happening on this line, conceptually?

use Log::Log4perl qw(get_logger)

Replies are listed 'Best First'.
Re: What is happening here?
by choroba (Cardinal) on Mar 17, 2014 at 14:33 UTC
    See use for details. In short, during the compilation phase, Perl checks whether Log::Log4perl is already in %INC, if not, it searches @INC for it (Log/Log4perl.pm), compiles it (if the module returns a true value, the compilation phase continues, otherwise it stops), and calls its import with 'get_logger' as an argument. It usually imports the get_logger subroutine to the caller's namespace.

    BTW, a semicolon is missing at the end of the line.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: What is happening here?
by toolic (Bishop) on Mar 17, 2014 at 14:35 UTC
    You imported the get_logger function from the Log::Log4perl module, and now you may call it in your code.

    See also:

Re: What is happening here?
by kcott (Archbishop) on Mar 18, 2014 at 03:55 UTC

    G'day carlriz,

    You might also be interested in the Exporter module. It explains about the import list, that's qw(get_logger) in your example.

    There's also information on Specialised Import Lists, which you'll encounter from time to time, or may choose to use yourself. A common example is:

    use Some::Module qw{:all};

    -- Ken

Re: What is happening here?
by locked_user sundialsvc4 (Abbot) on Mar 17, 2014 at 16:41 UTC

    If you look at the documentation for any CPAN module, you might find that it supplies a lot of subroutine definitions that you really don’t want in your code.   Or, you may simply want to refer to a particular routine or set of routines, and to clearly document to the Gentle Programmer who will one day follow in your footsteps just where those routines are coming from.   This syntax uses the specified module, but then only exposes to view the subroutines that are named in the list ... not all of the subroutines that the module might contain.   And of course, in so doing, it explicitly identifies the origin of those routines ... which, BTW, is tremendously helpful in understanding unfamiliar-to-you code!

    See:   perldoc -f use