Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Using an undefined value as a hashref

by itub (Priest)
on Sep 09, 2005 at 21:13 UTC ( [id://490760]=note: print w/replies, xml ) Need Help??


in reply to Using an undefined value as a hashref

The trick is that variables created by "my" are not available until the next statement, as documented in perlsub:
The declared variable is not introduced (is not visible) until after the current statement. Thus, my $x = $x; can be used to initialize a new $x with the value of the old $x, and the expression my $x = 123 and $x == 123 is false unless the old $x happened to have the value 123 .

Replies are listed 'Best First'.
Re^2: Using an undefined value as a hashref
by ikegami (Patriarch) on Sep 10, 2005 at 04:04 UTC

    I don't think that's totally true. The variable name is not available until the next statement, but the variable itself is. Otherwise, I don't see how the following two statements would work:

    open(my $fh, ...); read($fh, my $buf='', ...);

    I think the problem here is that you can't auto-vivify the lvalue returned by my. Can anyone confirm or deny any of this?

      I'd guess it is because my returns the generated variable.

      Ordinary morality is for ordinary people. -- Aleister Crowley
Re^2: Using an undefined value as a hashref
by talexb (Chancellor) on Sep 09, 2005 at 21:16 UTC

    Wow.

    Thank you. I didn't know that. I've learned a new thing today. Cool.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-19 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found