Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the colon meaning in the qw declaration?

Tags:

perl

I am reading about Log4Perl from perl.com
In the tutorial it says: use Log::Log4perl qw(:easy);

What is the : in front of easy? Is it some kind of special syntax?

like image 936
Jim Avatar asked May 26 '13 13:05

Jim


2 Answers

It is special syntax, for Specialised Import Lists, specifically for export tags.

Here's the example exporter part of a module from that documentation

@EXPORT      = qw(A1 A2 A3 A4 A5);
@EXPORT_OK   = qw(B1 B2 B3 B4 B5);
%EXPORT_TAGS = (T1 => [qw(A1 A2 B1 B2)], T2 => [qw(A1 A2 B3 B4)]);

A user of that module could say:

use Module qw(:DEFAULT :T2);

to import all of the names from the default set (@EXPORT) plus the ones defined in the T2 set.

Unless...

the package in question overloads the import sub and does whatever it wants with the option, which is what this package seems to do according to amesee's answer.

like image 111
Mat Avatar answered Nov 03 '22 20:11

Mat


This is not a special perl syntax. It's just some prefix determined by the author that makes this string look more like a value for configuration. You can see for yourself in the import definition. It just looks for the existence of a value in a hash with the key of :easy. Just a string consisting of characters ':', 'e', 'a', 's', 'y'.

like image 28
James Avatar answered Nov 03 '22 19:11

James