That's simply one convenient way of providing a list of arguments to the module. use strict qw/vars subs/; is equivalent to use strict 'vars', 'subs';.
Arguments to module loading are often handled by Exporter.pm to guide function import by the use-ing namespace.
After Compline, Zaxo
| [reply] [d/l] [select] |
qw() creates a list by splitting the contents on whitespace. You can use it any place you can use a list. See "Regexp Quote-Like Operators" in perlop.
| [reply] [d/l] |
The answer is quite simple: qw forms a list, not an array. That list can be assigned to an array, of course.
@test = qw/words go here/; is exactly equivlent to @test = ('words', 'go', 'here');. As another poster mentioned, use takes a list argument, which is passed to the import method of the module being used.
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
| [reply] [d/l] [select] |
perldoc -f use
use Module VERSION LIST
use Module VERSION
use Module LIST
use Module
use VERSION
Imports some semantics into the current package from the named
module, generally by aliasing certain subroutine or variable
names into your package.
perldoc perldata
the resulting list value is interpolated into LIST just as if each
individual element were a member of LIST. Thus arrays and hashes lose
their identity in a LIST--the list
(@foo,@bar,&SomeSub,%glarch)
contains all the elements of @foo followed by all the elements of @bar,
Update:So what happens is, that the array build using qw is, don't know how to put it, transformed into a list if given as an argument to use.
++theorbtwo, missed to scann the relevant docs :)
perldoc perlop
qw/STRING/
Evaluates to a list of the words extracted out of STRING, using
embedded whitespace as the word delimiters.
regards,
tomte
Hlade's Law:
If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.
| [reply] |
Just to add to the comments about qw() and lists and import. There are many modules and situations where it is common not to use qw(), prefering to use key=>VALUE, pairs like
use constant DEBUG=>1;
and the quoting usual for that style. However, Exporter's behaviour and the general needs of the import interface often mean that that style is not convenient, and so qw() becomes common. There are other Exporter style modules that have different syntaxes, where I imagine qw() ends up being used less often.
---
demerphq
<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
| [reply] [d/l] [select] |
You see it a lot when you need a function that isn't exported by default.
For example
use CGI qw/escape unescape/;
allows you to use the escape and unescape functions as if you had defined them in your namespace.
use strict;
use CGI qw/escape unescape/;
my $escval = escape('test script');
print "Escaped: $escval\n";
my $val = unescape($escval);
print "Unescaped: $val\n";
Outputs
Escaped: test%20script
Unescaped: test script
| [reply] [d/l] [select] |
Thank you guys and gals for such a thorough explanation of the many uses of qw.... Thanks for taking a simple question so seriously.
| [reply] |