DEV Community

Discussion on: Tools for learning Perl context

Collapse
 
matthewpersico profile image
Matthew O. Persico

TIL...
I thought the 'value' of a hash must be a scalar value. So I ran:

$ perl -de 42
  DB<5> @arr= qw ( x y z)
  DB<6> $href = { key => @arr }
  DB<7> x $href
0  HASH(0x4068718)
   'key' => 'x'
   'y' => 'z'
Enter fullscreen mode Exit fullscreen mode

Boy, was I shocked when x $href did not yield:

0  HASH(0x4068718)
   'key' => 3
Enter fullscreen mode Exit fullscreen mode

The 'fat comma' fooled me.

Collapse
 
kfly8 profile image
kobaken

Thank you for your comment!
I empathize with your situation.

Collapse
 
grinnz profile image
Dan Book • Edited

The values of hashes indeed must be scalar values; the problem here (which has caused many problems and even vulnerabilities) is that the fat comma doesn't construct a hash, just a list.

Collapse
 
matthewpersico profile image
Matthew O. Persico

Let me rephrase - I assumed that the right hand side of a fat comma would have context scalar. However, since it just a comma, it has context list.