Exporter

Innerhalb Ihrer MyModule.pm-Datei:

package MyModule;

use strict;
use Exporter;

our $VERSION=1.00;              # Oder höher...
our @ISA = qw(Exporter);

our @EXPORT     = qw (f1 %h);   # Standardmäßig importierte Symbole.
our @EXPORT_OK  = qw (f2 f3);   # Nur bei Bedarf importierte Symbole.
our %EXPORT_TAGS = (            # Abbildungen für :shortcuts.
    a => [qw (f1 f2 f3)],
    b => [qw(f2 %h)],
);

# Ihr Code steht hier.

1;

In einem Programm oder einem anderen Modul, das Ihr Modul nutzt:

use MyModule; # Alles in @EXPORT importieren. use MyModule (); # Modul laden, nichts importieren. use MyModule "f1", "f2", "%h"; # Zwei Subroutinen und eine Variable. use MyModule qw (:DEFAULT f3); # Alles in @EXPORT + eine Subroutine. use MyModule "f4"; # Fatal, weil f4 nicht exporiert wurde. ...

Get Programmieren mit Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.