Re: my
by doran (Deacon) on Feb 03, 2001 at 06:30 UTC
|
I'm probably just dumb (okay, probably not probably), but it took me way too long to understand the difference between package variable and lexical variables.
An article that helped me greatly is one by Dominus called Coping with Scoping. Like I said, I found it very useful (as is often the case with Dominus' articles 'n stuff). Check it out if the above answers still leave you wondering, or even if they don't.
good luck
| [reply] [Watch: Dir/Any] |
|
how come all dominus' stuff is dead links?
i found the information on his site, but the his links from perlmonk aren't working. i got downvoted for asking, i guess. i have to be more careful.
| [reply] [Watch: Dir/Any] |
|
Dunno. You'll have to ask Dominus. It was working yesterday. Maybe he's upgrading. ;)
| [reply] [Watch: Dir/Any] |
Re: my
by autark (Friar) on Feb 03, 2001 at 04:44 UTC
|
You don't have to use my when
you use strict. If you predeclare your variables
using use vars (or our() with newer
perls), or if you fully qualify your variables ($main::foo),
use strict will not complain.
Since I'm not sure what you mean by sub scripts, I can't
fully answer your question, could you please specify more clearly
what you mean by sub scripts ?
Autark. | [reply] [Watch: Dir/Any] [d/l] [select] |
Re: my
by malaga (Pilgrim) on Feb 03, 2001 at 05:06 UTC
|
oh, and thanks, i'll look up "use" and the rest.
update:
why would i get downvoted for saying thank you? | [reply] [Watch: Dir/Any] |
|
You may also want to check out this node that I wrote up a while back on passing variables as arguments to a subroutine.
-marius
| [reply] [Watch: Dir/Any] |
Re: my
by malaga (Pilgrim) on Feb 06, 2001 at 04:10 UTC
|
now it's working. i don't know what that was about, but all of those hyperlinks were dead when i tried, except the one to his site. | [reply] [Watch: Dir/Any] |
|
The general hint is if a webpage (website) is down, you can look on google or something for a cached version. In this case, it's (google) Coping with Scoping.
The syntax to use for google's cache is:
http://www.google.com/search?q=cache:[hostname/page]
| [reply] [Watch: Dir/Any] [d/l] |
Re: my
by malaga (Pilgrim) on Feb 03, 2001 at 04:47 UTC
|
sorry, i meant subroutine. | [reply] [Watch: Dir/Any] |
|
There is no difference in using dynamic vs. lexical
variables as parameters to a function. Assuming perl5.6
(or greater):
use strict;
sub foo {
my $foo = shift;
print $foo;
}
my $my_var = "lexical bar";
our $our_var = "dynamic bar";
foo($my_var);
foo($our_var);
However, using dynamic variables may cause strange results
if not used with care. So using lexical variables is not a
bad idea at all.
Using references to lexical and dynamic variables is just the
same, except that you have to reference and dereference
the variables.
But please note that if you're not careful enough using
dynamic variables (those not declared with my),
strange results can appear, so if you can, use lexical
variables - that's probabely what you want anyway.
Autark. | [reply] [Watch: Dir/Any] [d/l] [select] |