| Subject: | Re: List with qw and without |
|---|---|
| From: | rob.dixon@xxxxxxx (Rob Dixon) |
| Date: | Sat, 26 Jul 2008 13:26:00 +0100 |
| Newsgroups: | perl.beginners |
William wrote:
> package MyConfig;
> use constant (DOCUMENT_ROOT => "/var/www/");
> require Exporter;
> our @ISA = qw(Exporter);
> our @EXPORT_OK = qw(DOCUMENT_ROOT); # This works
> #our @EXPORT_OK = (DOCUMENT_ROOT); # But this does not work
>
> 1;
>
> use MyConfig qw(DOCUMENT_ROOT);
> print DOCUMENT_ROOT;
>
> # If I do not use qw , I will get error of "DOCUMENT_ROOT" is not exported by
> the MyConfig module
> # Why is qw importance is so significance here ?
> # I thought qw is just a syntatic sugar of perl to make a list
> # Thank you.
That's correct. qw splits its parameter on whitespace, so
qw(A B C)
is similar to
split ' ', 'A B C'
So if you write
use MyConfig 'DOCUMENT_ROOT';
or
use MyConfig ('DOCUMENT_ROOT');
then your program will work as expected. But because you've defined the constant
DOCUMENT_ROOT to be "/var/www/"
use MyConfig (DOCUMENT_ROOT);
is the same as saying
use MyConfig ("/var/www/");
which is nonsense.
HTH,
Rob
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | List with qw and without, William |
|---|---|
| Next by Date: | Re: while trying to learn pack, Richard Lee |
| Previous by Thread: | List with qw and without, William |
| Next by Thread: | Pipe print output into shell in debugger, Marek |
| Indexes: | [Date] [Thread] [Top] [All Lists] |