Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- PERL 4.0 Reference Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

     do BLOCK

             Returns  the  value  of  the  last  command  in  the
             sequence of commands indicated by BLOCK.  When modi-
             fied by a loop modifier,  executes  the  BLOCK  once
             before   testing  the  loop  condition.   (On  other
             statements the loop modifiers test  the  conditional
             first.)

     do SUBROUTINE (LIST)

             Executes a SUBROUTINE declared by a sub declaration,
             and   returns  the  value  of  the  last  expression
             evaluated in SUBROUTINE.  If there is no  subroutine
             by  that name, produces a fatal error.  (You may use
             the "defined" operator to determine if a  subroutine
             exists.)  If you pass arrays as part of LIST you may
             wish to pass the length of the  array  in  front  of
             each  array.   (See the section on subroutines later
             on.)  SUBROUTINE may be a scalar variable, in  which
             case  the  variable contains the name of the subrou-
             tine to execute.  The parentheses  are  required  to
             avoid confusion with the "do EXPR" form.

             As an alternate form, you may call a  subroutine  by
             prefixing  the  name with an ampersand: &foo(@args).
             If you aren't passing any arguments, you don't  have
             to use parentheses.  If you omit the parentheses, no
             @_ array is passed to the subroutine.  The & form is
             also  used to specify subroutines to the defined and
             undef operators.

     do EXPR Uses the value of EXPR as a  filename  and  executes
             the contents of the file as a perl script.  Its pri-
             mary use is to include subroutines from a perl  sub-
             routine library.

                  do 'stat.pl';

             is just like

                  eval `cat stat.pl`;

             except that it's more efficient, more concise, keeps
             track  of  the  current filename for error messages,
             and searches all the -I libraries if the file  isn't
             in the current directory (see also the @INC array in
             Predefined Names).  It's the same, however, in  that
             it  does reparse the file every time you call it, so
             if you are going to use the file inside a  loop  you
             might  prefer to use -P and #include, at the expense
             of a little more startup time.   (The  main  problem
             with #include is that cpp doesn't grok # comments--a
             workaround is to use ";#" for standalone  comments.)
             Note that the following are NOT equivalent:

                  do $foo;  # eval a file
                  do $foo();     # call a subroutine

             Note that inclusion of library  routines  is  better
             done with the "require" operator.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson