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
How can I display all array element in which each element will display on next line in perl ?
What does this symbol mean '->'?
What is the difference between perl list and perl array?
What is the use of strict?
Why is it hard to call this function: sub y { "because" } ?
How to get help for perl?
Differentiate between use and require, my and local, for and foreach and exec and system
How do I replace every TAB character in a file with a comma?
What are arrays in perl?
How does polymorphism work in perl?
How can you call a subroutine and identify a subroutine?
Why to use perl?
What rules must be followed by modules in perl.
what are the three groups involved in information sharing?
How do I print the entire contents of an array with Perl?