http://qs1969.pair.com?node_id=617375


in reply to Re: Not quite understanding a couple of things
in thread Not quite understanding a couple of things

Thank you very much, that explained a lot to me. I get it now. @others: Yes, I am at the beginning of my PERL journey, and I thank everyone who posted.

Replies are listed 'Best First'.
Re^3: Not quite understanding a couple of things
by blazar (Canon) on May 25, 2007 at 08:28 UTC
    Thank you very much, that explained a lot to me. I get it now. @others: Yes, I am at the beginning of my PERL journey, and I thank everyone who posted.

    Lesson #1: it's not PERL, but either Perl or perl. See also PERL as shibboleth and the Perl community. However, to expand on the answers you got thus far: yes, $_ and @_ are special variables, described along with all the other special vars in perldoc perlvar. While it is true that the former is the default scalar variable in the sense that many constructs default to it, I wouldn't go so far as to say that the latter is the "default array": in fact it is much a technical device for parameter passing in subs, which in Perl 5 is in fact both extremely simple and has far reaching consequences. In Perl 6 by contrast @_ will still be there but thanks to the much more complex and powerful mechanism for parameter passing, you won't need most of the time. Back to 5, you can still use @_ as a generic array, but as someone said, this kind things smells. One situation in which you may want to assign to @_ is when you want to use magic goto (BTW: don't you ever use non-magic one), but that is an advanced topic that I would postpone to a much later lesson.

    In your OP you also write "I also do not quite understand how to work a hash." Well, this is a very basic Perl topic covered in the first few chapters or pages of any introductory book or tutorial. So I'm not even trying to explain to you how to work with a hash in Perl in any detail, because for sure there are lots of people already doing that far better than I ever could. I'll just tell you what a hash is: a mapping from some finite set (of strings) into some other (also finite, for obvious reasons) set, implemented in such a way that lookup is generally quite fast (but generally you don't care at all).