>>108364768
skill issue
The sub signatures are kind of too new to be used universally, and prototypes (the old thing) are retarded.
The sigils are meaningful. @ is a list context. $ is a scalar context. % is a hash context. & is sub context. * is a glob.
The map is just a list with key value pairs interleaved.
You can "cast" a type by referring to it in a different context.
References are scalar, it's like a pointer to referential (object) type.
It's needed, because basically you can't aggregate non-scalars in collections.
When you use () syntax for lists, you are concatenating things into one list.
If you want to actually store list inside a list/hash you need a scalar -> a reference.
You don't need references to scalars, because scalars are already scalars.
Subs arguments are just a list. It makes sense, it's like program's ARGV equivalent for the function.
Dereference syntax is not "confusing". You are referencing a variable in that particular context.
If the variable is a ref that contains a list and you want a list, you use @ to dereference it.
If the ref is a hash, you use a % to dereference it. There is nothing confusing about it.
The perl objects are actually a particular context's binding to the name.
When you declare a "type" you are just binding that variable to the name in that particular context.
That might be the confusing part, because you can reuse the name for another context.
In that case it's allocating an object in that particular slot (of the *glob) under that name.
my $foo = "bar";
my @foo = ($foo, 1, 2, 3);
my @bar = ($foo, \@foo, [4, 5, 6], 7, 8, 9);
print "just foo: $foo\n";
print "foo list: ( ";
for (@foo) { print " $_"; }
print " )\n";
print "bar list: ( ";
for (@bar) {
if (ref($_) eq "ARRAY") {
print " ( ";
for my $e (@{$_}) {
print " $e";
}
print " ) ";
} else { print " $_" };
}
print " )\n";
print "bar elements as scalars (refs): ( ";
for (@bar) { print " $_"; }
print " )\n";