Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Lexical scoping like a fox

by shmem (Chancellor)
on Jan 13, 2008 at 19:07 UTC ( [id://662205]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Lexical scoping like a fox
in thread Lexical scoping like a fox

1)using input record separator as newline indicator is very interesting. Never seen it before but works well. Any reason? I am assuming it's just a style issue?

I guess it's more along "a \n is a \n is a \n" - $/ is a global, and that could be changed far away without you knowing it; so it's more safety than style.

2)Below code from tutorial does not work when I insert my next to variable.. can someone explain this?

You are allocating a lexical $x, not a package global (which would be either use vars '$x' or our $x), and local aliases only package globals. You can't (shouldn't) allocate globs and lexicals of the same name in the same scope:

our $x; my $x; # gives a warning
our $x; { my $x; # ok }
3)can someone explain further on "lexical variables are declared at compile-time, not initialised? Is this because BEGIN runs during compile-time? I sneaked in a new my $foo = something inside of BEGIN block and execution of the code came out w/ foo is something during BEGIN phase

"lexical variables are declared at compile-time, not initialised" means "the container is created, but nothing is put into it". The initialization (= puting something into the bucket) happens at run time. BEGIN blocks are compiled and immediately run, that's why "code came out w/ foo is something during BEGIN phase".

See also my/local, space/time (was: Re: The difference between my and local).

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://662205]
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: (2)
As of 2024-04-25 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found