Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Perl Anomaly

by Akira71 (Scribe)
on Jan 14, 2005 at 17:51 UTC ( [id://422332]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Anomaly
in thread Perl Anomaly

Just as a side note, I decided to force the variable $c into the symbol table using use vars qw{$c}; and then the use of my works in the first case.

Not practicle, but enjoyable to look into.

Replies are listed 'Best First'.
Re^3: Perl Anomaly
by Errto (Vicar) on Jan 15, 2005 at 02:46 UTC
    and then the use of my works in the first case.
    This seems unlikely. What happens when you declare a variable with "our" or "use vars" and then declare it again with "my" is that the second one essentially replaces the first one for the remainder of that scope. So if you refer to the variable through a sympolic reference, you get the global one, but if you refer to it directly you get the lexical one. For example,
    use vars qw($B); my $A='B'; my $B=7; my $C=${$A}; print "A = $A - B = $B - C = $C\n";
    prints "A = B - B = 7 - C =" This happens because no value is ever assigned to the global variable called $B. Wacky, huh?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://422332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found