FAQ 7.2 What are all these $@%&* punctuation signs, and how do I know when to use them?

Discussion in 'Perl Misc' started by PerlFAQ Server, Feb 19, 2011.

  1. 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.
    PerlFAQ Server, Feb 19, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anonieko

    HttpHandlers - Learn Them. Use Them.

    Anonieko, Jun 15, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    507
    tdavisjr
    Jun 16, 2006
  2. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    223
    Gregory Toomey
    Apr 23, 2004
  3. PerlFAQ Server
    Replies:
    0
    Views:
    101
    PerlFAQ Server
    Feb 9, 2011
  4. Replies:
    14
    Views:
    337
    David Mark
    Sep 28, 2008
  5. Peng Yu
    Replies:
    2
    Views:
    280
    Peter Makholm
    Dec 4, 2012
Loading...

Share This Page