What is the "my $item = $currentDeal{other}{ $args-" means ?

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

What is the "my $item = $currentDeal{other}{ $args-" means ?

#1 Post by sofax222 »

In the src/Network/Receive/ServerType0.pm file.
The subroutime : deal_add_other

What is the statement means:

Code: Select all

my $item = $currentDeal{other}{ $args->{nameID} } ||= {};
I can not figure out this statement ?
I never seen the syntax like this ?

Would you giive me some help of explain ?
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: What is the "my $item = $currentDeal{other}{ $args-" means ?

#2 Post by EternalHarvest »

If the double assignment confuses you, it's the same as:

Code: Select all

$currentDeal{other}{ $args->{nameID} } ||= {};
my $item = $currentDeal{other}{ $args->{nameID} };
sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

Re: What is the "my $item = $currentDeal{other}{ $args-" means ?

#3 Post by sofax222 »

EternalHarvest wrote:If the double assignment confuses you, it's the same as:

Code: Select all

$currentDeal{other}{ $args->{nameID} } ||= {};
my $item = $currentDeal{other}{ $args->{nameID} };
Not double assignment !

I can not figure out what is " ||= {};"
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: What is the "my $item = $currentDeal{other}{ $args-" means ?

#4 Post by EternalHarvest »

The same as with "a += b" etc:

Code: Select all

$currentDeal{other}{ $args->{nameID} } = $currentDeal{other}{ $args->{nameID} } || {}
{} is a reference to a new empty hash here.
sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

Re: What is the "my $item = $currentDeal{other}{ $args-" means ?

#5 Post by sofax222 »

I got it !
It is a increasement of hash reference !

Thxs a lot !
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: What is the "my $item = $currentDeal{other}{ $args-" means ?

#6 Post by EternalHarvest »

sofax222 wrote:It is a increasement of hash reference !
No, wait. And you can't "increment" references in Perl.
A ||= B is the same as A = A || B.
sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

Re: What is the "my $item = $currentDeal{other}{ $args-" means ?

#7 Post by sofax222 »

Thxs again !