[25993] in Perl-Users-Digest
Perl-Users Digest, Issue: 8212 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 29 03:05:23 2005
Date: Wed, 29 Jun 2005 00:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 29 Jun 2005 Volume: 10 Number: 8212
Today's topics:
What does +FOO mean? <BLOCKSPAMfishfry@your-mailbox.com>
Re: What does +FOO mean? <john@castleamber.com>
Re: What does +FOO mean? <tassilo.von.parseval@rwth-aachen.de>
Re: What does +FOO mean? <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 28 Jun 2005 21:03:20 -0700
From: fishfry <BLOCKSPAMfishfry@your-mailbox.com>
Subject: What does +FOO mean?
Message-Id: <BLOCKSPAMfishfry-7FB93D.21032028062005@comcast.dca.giganews.com>
I'm looking at a lot of code where they have
use constant FOO => "foo";
and then later
my $hash{+FOO} ...
Can someone please explain what '+' signifies in this context?
------------------------------
Date: 29 Jun 2005 04:08:07 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: What does +FOO mean?
Message-Id: <Xns9683EB156FA51castleamber@130.133.1.4>
fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
> I'm looking at a lot of code where they have
>
> use constant FOO => "foo";
>
> and then later
>
> my $hash{+FOO} ...
>
> Can someone please explain what '+' signifies in this context?
$hash{FOO} is $hash{'FOO'}
$hash{+FOO} is $hash{"foo"}
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Wed, 29 Jun 2005 07:09:55 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: What does +FOO mean?
Message-Id: <slrndc4b93.qu.tassilo.von.parseval@localhost.localdomain>
Also sprach fishfry:
> I'm looking at a lot of code where they have
>
> use constant FOO => "foo";
>
> and then later
>
> my $hash{+FOO} ...
>
> Can someone please explain what '+' signifies in this context?
Barewords in hash subscripts are treated by perl as strings. By writing
'{+FOO}' the subscript no longer qualifies as bareword and the Perl
interpreter then knows it is referring to an identifier, the constant
FOO.
Other ways to resolve this would be:
$hash{FOO()}
$hash{&FOO}
This works because under the hood constants are inlineable functions
(that is: functions with an empty prototype created at compile-time).
By the way:
my $hash{+FOO} ...
is a syntax-error. You cannot declare hash-elements with 'my'.
Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
------------------------------
Date: Wed, 29 Jun 2005 00:23:19 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: What does +FOO mean?
Message-Id: <slrndc4c27.8ej.tadmc@magna.augustmail.com>
John Bokma <john@castleamber.com> wrote:
> fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote:
>
>> I'm looking at a lot of code where they have
>>
>> use constant FOO => "foo";
>>
>> and then later
>>
>> my $hash{+FOO} ...
>>
>> Can someone please explain what '+' signifies in this context?
>
> $hash{FOO} is $hash{'FOO'}
> $hash{+FOO} is $hash{"foo"}
$hash{ FOO() } is $hash{"foo"} too.
(but the OP's "my $hash{+FOO}" isn't even Perl...)
The perl parser intuit()s that the FOO is a string, if you want it
to be a subroutine call instead (which is how "use constant"
implements constants), then you need to disambiguate it somehow
so that you get your desired semantic.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8212
***************************************