Home: Perl Programming Help: Beginner:
need help



karuperl
New User

May 14, 2018, 10:16 AM


Views: 2730
need help

I am new to perl and learning please help me what does this mean

i have a condition that mention as

&& !(exists $orra_dta->{$nm_id}->{'XY_IP_ID'})

also below one

$orra_dta->{$nm_id}->{'XY_IP_ID'} = $orra_dta->{$nm_id}->{'ID_NM'}


Chris Charley
User

May 14, 2018, 3:20 PM


Views: 2727
Re: [karuperl] need help

The '&&' is anding the (unseen) condition preceding the statement '!(exists $orra_dta->{$nm_id}->{'XY_IP_ID'}) '.

'!(exists $orra_dta->{$nm_id}->{'XY_IP_ID'}) ' is saying if not exists the key 'XY_IP_ID' in the hash ' $orra_dta->{$nm_id}'.

Your statement in question is most likely followed by an action like:

Code
if (black && blue) { 
apply ointment
}

The line '$orra_dta->{$nm_id}->{'XY_IP_ID'} = $orra_dta->{$nm_id}->{'ID_NM'}' is assigning the value associated with hash key ''ID_NM' to the the hash element keyed by 'XY_IP_ID'.


Chris Charley
User

May 17, 2018, 4:33 PM


Views: 2712
Re: [karuperl] need help

Hi

I realize that my previous reply may not have been so helpful, so I'll try again.

Making a wild guess, perhaps your code looks like this.

Code
if (exists $orra_dta->{$nm_id} && !(exists $orra_dta->{$nm_id}->{'XY_IP_ID'}) { 
$orra_dta->{$nm_id}->{'XY_IP_ID'} = $orra_dta->{$nm_id}->{'ID_NM'};
}


The first condition exists $orra_dta->{$nm_id} checks to see if '$nm_id' exists as a key in the hash. If it does, then a check is made !(exists $orra_dta->{$nm_id}->{'XY_IP_ID'}) to see if 'XY_IP_ID' doesn't exist in the hash. It checks the first condition before the second condition to avoid auto vivifying the 'first' key before trying the second condition.

If both conditions are true, then an assignment is made, i.e., $orra_dta->{$nm_id}->{'XY_IP_ID'} = $orra_dta->{$nm_id}->{'ID_NM'}

As I said, this is just a guess at what code you are using.


(This post was edited by Chris Charley on May 17, 2018, 4:36 PM)