while(my($key, $value) = each(%hash) ) { print "$key =>
$value\n"; }
my($key, $value); while(($key, $value) = each(%hash) ) {
print "$key => $value\n"; }
What is the different between these two code in case of "my"
usage ?
Answer Posted / sourisengupta
case 1:
by decalring "my" we are making the variable local.
So you cant access the value of those variable from the
outsite of that block.
case 2:
here you can access the value of the code from the
outside of that code.
"my" is generally used to protect the variable from
mingling.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
What is the importance of perl warnings?
You want to connect to sql server through perl. How would you do that?
When would `local $_' in a function ruin your day?
What does 'do' statement do in perl?
How to read a file into a hash array?
Write a program to download the contents from www.perlinterview.com/answers.php website in Perl.
What is Perl?
What is perl? What is the basic command to print a string in perl?
What syntax is used for grep() function?
What is the use of -t?
Create a function that is only available inside the scope where it is defined ?
Explain the difference between "my" and "local" variable scope declarations. ?
Can inheritance be used in perl?
Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.
How to determine strings length in perl?