Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Lexical scoping like a fox

by shmem (Canon)
on Jan 13, 2008 at 19:07 UTC ( #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}


Comment on Re^4: Lexical scoping like a fox
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-12-22 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls