in reply to Understanding difference between my and local variables.

I don't understand why you are asking questions 1 to 4. Surely it's easier to try out whether it's possible than typing in the question?

As for 5), the answer is, "it's not really a sensible question". Global variables have to do with scope - a variable is global if it can be accessed from the outer scope. Lexical (my) can, if declared appropriately. Package variables always can (obviously), but they don't need to be declared - from a language point of view, they always exist. "use vars" is just a way of telling Perl "in this scope, I'm going to use these package variables, and I'm not going to refer to them by their full name" (use vars will have some effects in perl - but that's implementation, not language).

As for 6), there's no difference. But there is a difference between my($x, $y); and my $x, $y;. The former is equivalent to my $x; my $y;, the latter to my $x; $y;.

I do not understand question 7). Where is my $c?

8) you can just try out for yourself.

Replies are listed 'Best First'.
Re^2: Understanding difference between my and local variables.
by ikegami (Patriarch) on Oct 15, 2010 at 07:29 UTC
    >perl -E"say scalar( my $x = qw( a b c ) );" c >perl -E"say scalar( my ($x) = qw( a b c ) );" 3
      The question wasn't what the difference is between my ($x) = ..." and my $x = ..... The question was what the difference is between my ($x); and my $x;.

        Technically true, but I believe you're wrong in thinking he's going to realize the semi-colon was meaningful (assuming he even remembers that he used a semi-colon).