Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > local variables and global variables

Reply
Thread Tools

local variables and global variables

 
 
king
Guest
Posts: n/a
 
      06-27-2006
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

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      06-27-2006
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


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      06-27-2006
king <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can local function access local variables in main program? Sullivan WxPyQtKinter Python 10 11-08-2007 02:51 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
NB question on global/local variables in functions Wolfgang Python 1 07-17-2006 12:04 PM
allocation alignment for global and local variables. gamja C Programming 4 09-30-2005 10:42 PM



Advertisments