|Think about Loose Coupling|
Use of "my" after Perl v5.14by Rohit Jain (Sexton)
|on Sep 20, 2012 at 21:45 UTC||Need Help??|
Rohit Jain has asked for the
wisdom of the Perl Monks concerning the following question:
What is difference between: -while( my($index, $value) = each @rocks )
andwhile((my $index,my $value) = each @rocks )
I have read that "my" is used for creating private variables in a subroutine.
But if we use "use v5.14" then using "my" is compulsory whenever we are creating variable for the first time. Then in that case, if a variable is declared for the first time in a subroutine, it has to be private always(forcefully due to v5.14)
So how do we declare a non-private variable(global variable) in Subroutine.. At first it didn't make sense to me to have global variables in a subroutine.. But it is a topic in a book..
So is there any major signifance of "my" in Perl
And Yes.. I am Overwhelmed by how length of an array is easily replaced in a scalar context.. No function needed at all.. Wow!! :) :)