1

Can anyone explain what happened in background for this code? Code:

%d=('sa',1);
$x=%d;
print "$x";

Output:

1/8

Code2:

%d=('sa',1,"da"=>2,"daa",3);
$x=%d;
print "$x";

Output:

3/8
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • 1
    hash buckets used / hash buckets allocated – xxfelixxx Nov 14 '17 at 07:28
  • This is not generally a useful feature, except to see if the hash is empty or not. – xxfelixxx Nov 14 '17 at 07:29
  • The fat comma `=>` in your second example is equivalent to a regular comma `,` and is often used in hash declarations for readability. – xxfelixxx Nov 14 '17 at 07:31
  • 3
    Downvoting this question is a disservice to the community. It has a useful title, simple description, and the link to the duplicated question is likely to help people who come from Google. – giusti Nov 14 '17 at 11:28
  • Not an exact duplicate: this questions seems to me asking how to assign a hash to a scalar variable; knowing what is actually happening when they try doesn't tell them how to do it correctly – ysth Nov 15 '17 at 02:06
  • Thanks @giusti , ysth and xxfelixxx. And giusti your response gives a hope to new learners like me. – tester unknown Nov 15 '17 at 08:51

0 Answers0