Re: Getting a / when regex should produce nothing

Torsten Förtsch <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
On Tuesday 27 April 2010 10:18:17 Michael Ludwig wrote:

> A lexical variable in Perl is any variable declared with "my", regardless
>  of the scope, which may be file-level. Unlike globals, lexical variables
>  aren't directly accessible from outside the package.

Not quite correct. Consider this:

$ perl -Mstrict -le '
  my $x=10;
  our $y=20;
  {
    package hugo;

    print "x=$x";   # references $x outside of package hugo
    print "y=$y";   # references $main::y
    ($x,$y)=(1,2);
  }
  print "x=$x";
  print "y=$y"
'
x=10
y=20
x=1
y=2

$x is file-level lexical. It is visible all over the file. The embedded 
package hugo has no influence. Lexical variables are not bound to a package 
but to a lexical scope.

Same with our-variables. C<our> declares the visibility of a variable in the 
current lexical scope.

> You can read up about this issue here:
> 
> http://perl.apache.org/docs/general/perl_reference/perl_reference.html

Or for German speakers, there was a series of articles about scoping in $foo-
magazin:

  http://foo-magazin.de/

Torsten Förtsch

-- 
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.