Re:On the Decline of Perl – external factors
by tyingq on Thursday April 01, 2021 @11:15AM
(#26661482)
Perl has sigils for different data types.
But, it also has references, like pointers.
So, you can put scalars into arrays and hashes, refs into hashes and arrays, etc, etc. At whatever nested depth you want. But you have to extract pieces later. And Perl, as usual, allows a zillion ways to do it. These are all exactly the same thing:
So imagine you need to extract a string that's at the bottom of some data structure. Here's an example:
I can extract something using different approaches, like:
[ Parent
| on HN ]
Re:On the Decline of Perl – external factors
by tripa on Thursday April 01, 2021 @12:05PM
(#26662310)
Or just the simple
$array_ref->[2][2][1];
Re:On the Decline of Perl – external factors
by tyingq on Thursday April 01, 2021 @12:14PM
(#26662453)
Yes, perhaps I shouldn't have gone with just nested arrays/arrayrefs :)
Here's a modified example where it's not as clear how to deref.
Like:
@IP = ('192.168.1.10','192.168.1.15');
@PORT = ("5000","5002");
@TCP = ("Q931","H225","H245");
%TAGS = (L2 =>"ETHERNET",L3=>"IP",L4=>\@TCP);
@PKT = ( \@IP, \@PORT, \%TAGS);
$array_ref=\@PKT;
print $array_ref->[2]{L4}[0];# this works
print $$array_ref[2]{L4}[0]; # this works
print $array_ref[2]{L4}[0]; # this doesn't