Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Perl has symbols do represent lists(@), associative arrays(%), scalars($).

It's been a long time since I last programmed in Perl, but as I recall the confusing part was that for instance a list might use @ or $ depending on what you're doing with it, and the same for associative arrays, which might use % or $ depending on what you're doing with it; the same variable might use different sigils in different parts of your code, instead of staying with the same sigil for its whole lifetime.



The sigil represents the type of the thing you're accessing, not the type of where it comss from.

$ means a scalar (number, string, reference)

@ means an array/list

% means a hash (also known in other languages as a map, associative array, etc)

A list item and hash keys and values are all scalars. So the array is @foo, but the items are $foo[0], etc. References get a bit ugly if you need to access a whole container whose reference is stored in another container, and also if references are used gratiutously: I've worked in code where no arrays or hashes were used, only ArrayRefs and HashRefs, ugh.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: