local variables and global variables

Discussion in 'Perl Misc' started by king, Jun 27, 2006.

  1. king

    king Guest

    Hi,
    How and what should be used to define a local variable and a global
    variable as well.

    and if i have used a sub-routine in a script and i want to use that
    sub-routine in another script,
    how can i do that.

    regards
    king, Jun 27, 2006
    #1
    1. Advertising

  2. king wrote:
    > How and what should be used to define a local variable and a global
    > variable as well.


    In Perl variables are defined by assigments. You simply do
    $var = <expr>;

    > and if i have used a sub-routine in a script and i want to use that
    > sub-routine in another script,
    > how can i do that.


    You define the subroutine in a module and then import that module in both
    scripts.

    jue
    Jürgen Exner, Jun 27, 2006
    #2
    1. Advertising

  3. king <> wrote:

    > How and what should be used to define a local variable and a global
    > variable as well.



    A local() variable *is* a global variable in Perl.

    See:

    "Coping with Scoping":

    http://perl.plover.com/FAQs/Namespaces.html


    > and if i have used a sub-routine in a script and i want to use that
    > sub-routine in another script,
    > how can i do that.



    By using a "module":

    perldoc -q module

    What modules and extensions are available for Perl? What is CPAN?
    What does CPAN/src/... mean?

    How do I find which modules are installed on my system?

    How do I create a module?

    How do I install a module from CPAN?

    How do I keep my own module/library directory?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jun 27, 2006
    #3
    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. Wolfgang
    Replies:
    1
    Views:
    268
    Bruno Desthuilliers
    Jul 17, 2006
  2. gamja
    Replies:
    4
    Views:
    311
    Christian Bau
    Sep 30, 2005
  3. Sullivan WxPyQtKinter
    Replies:
    10
    Views:
    660
    Antoon Pardon
    Nov 8, 2007
  4. Tim Rau

    global/local variables

    Tim Rau, Jan 24, 2008, in forum: Python
    Replies:
    8
    Views:
    449
    Tim Rau
    Jan 25, 2008
  5. danep2
    Replies:
    1
    Views:
    294
    Erik Wikström
    Apr 13, 2008
Loading...

Share This Page