--On Tuesday, September 30, 2003 11:31 -0700 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

How do you declare a var global versus local? It seems variables a
local and not static as in shell. That is, the sub does not see the
vars from the calling part. So, can someone modify the snipet to
make it work?

Varibles are by default global, and variable...


a.pl
------
# my $x; any diff from the next line?
$x="abc";

doMe

sub doMe
{ $x="xyz";
  print $x; #will print out xyz
  How can I get the "$x=abc" here w/o passing as an arg?
}

You want the sub to see the $x from outside? Easy: just don't change $x's value...


What you've done here is declare a variable $x, assign it the value "abc", then assign it the value "xyz" and print it out. If you wanted "abc" you shouldn't have assigned it "xyz".

Varibles vary in perl. Don't expect them not to. (You can create a constant at compile time, but that is not a variable.)

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to