3 ms·
Perl might be weird, but it's logic and it makes sense. References are not automagical, but explicit, so you don't get an inconsistent function calling model. I
by qalmakka 5y ago
Perl might be weird, but it's logic and it makes sense. References are not automagical, but explicit, so you don't get an inconsistent function calling model. If you call a sub like `something(%h)`, it will get a copy of the hash. If you use `something(\%h)` the sub will receive a reference to access the hash instead. This is way better than Python or Java where everything is "pass-by-reference" until it isn't, and the fact a function won't modify the arguments you passed to it is basically a gentleman's agreement.
Perl is complex, but it is also rewarding when you use it for those tasks it's good at (like gluing code together and text processing).
- datameta 5y agoIve only used Perl for one story at work but I don't fully grok yet why we $ a @ or a % Getting a hash passed by ref to a sub was a true syntactic challenge that I haven't experienced in a different language. Have to say though, using regex in Perl is chef's kiss
- qalmakka 5y agoBecause an array is a list of scalar, and an hash a map of scalars. If you want to access a scalar inside the list, you write $a[1], which means "the scalar at the first position of list @a". If it was @a[1] it would have been inconsistent, because then a @ expression would have returned a scalar and not a list.