Prev: FAQ 7.21 How do I redefine a builtin function, operator, or method?
Next: FAQ 9.19 How do I return the user's mail address?
From: PerlFAQ Server on 12 Apr 2010 00:00 This is an excerpt from the latest version perlfaq7.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 7.2: What are all these $@%&* punctuation signs, and how do I know when to use them? They are type specifiers, as detailed in perldata: $ for scalar values (number, string or reference) @ for arrays % for hashes (associative arrays) & for subroutines (aka functions, procedures, methods) * for all types of that symbol name. In version 4 you used them like pointers, but in modern perls you can just use references. There are couple of other symbols that you're likely to encounter that aren't really type specifiers: <> are used for inputting a record from a filehandle. \ takes a reference to something. Note that <FILE> is *neither* the type specifier for files nor the name of the handle. It is the "<>" operator applied to the handle FILE. It reads one line (well, record--see "$/" in perlvar) from the handle FILE in scalar context, or *all* lines in list context. When performing open, close, or any other operation besides "<>" on files, or even when talking about the handle, do *not* use the brackets. These are correct: "eof(FH)", "seek(FH, 0, 2)" and "copying from STDIN to FILE". -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod. |