Perl Language Packages and modules Using a module

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

use Cwd;

This will import the Cwd module at compile time and import its default symbols, i.e. make some of the module's variables and functions available to the code using it. (See also: perldoc -f use.)

Generally this is will do the right thing. Sometimes, however, you will want to control which symbols are imported. Add a list of symbols after the module name to export:

use Cwd 'abs_path';

If you do this, only the symbols you specify will be imported (ie, the default set will not be imported).

When importing multiple symbols, it is idiomatic to use the qw() list-building construct:

use Cwd qw(abs_path realpath);

Some modules export a subset of their symbols, but can be told to export everything with :all:

use Benchmark ':all';

(Note that not all modules recognize or use the :all tag).



Got any Perl Language Question?