Re: use constant, Perl question
[email protected] (Bjoern Hoehrmann) Sat, 02 Jul 2011 08:04:16 +0200
| Newsgroups | perl.libwww |
|---|---|
| Message-ID | <[email protected]> |
* Gary Yang wrote:
>I have hard time of understanding “use constant”. I do not understand
>why place the “+” in front of constant variable. See the code below. In
>the for loop, It adds “+” (+kAWSAccessKeyId,). In the new function call,
>it adds the “+” (+RequestSignatureHelper::kAWSAccessKeyId => myAWSId). I
>read the perldoc of “use constant”. But, no clue. Can someone explain
>what it mean? Or point me any books or URLs I can read. I got the code
>below from some samples. If this mailing list is not the proper place to
>ask this question, please tell me which mailing list is best for this
>question. Thanks.
This mailing list is dedicated to libwww-perl related issues, general
questions about Perl programming would be better placed on forums like
http://www.perlmonks.org/ or the comp.lang.perl.* newsgroups on Usenet.
As for your question, many of the "+" in the script are redundant, so
they are likely there for reasons of consistency. Sometimes you can use
the operator to force a particular interpretation, for instance,
print +('xxx'), ('yyy');
will print 'xxxyyy' but without the "+" you get 'xxx'. Similarily,
>$self->{+kRequestMethod}
The `constant.pm` module installs subroutines for the constants you
register, so this is read as a function call
$self->{ kRequestMethod() }
while without the "+" it would be read as a string literal like
$self->{ "kRequestMethod" }
I hope that helps,
--
Björn Höhrmann · mailto:[email protected] · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/