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 ?



while(my($key, $value) = each(%hash) ) { print "$key => $value\n"; } my($key, $valu..

Answer / 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

More CGI Perl Interview Questions

Write syntax to use grep function?

0 Answers  


Define operators used in perl?

0 Answers  


What does length(%HASH) produce if you have thirty-seven random keys in a newly created hash?

0 Answers  


How many ways can we express string in Perl?

0 Answers  


How to close a file in perl?

0 Answers  






Is perl a case sensitive language?

0 Answers  


Can inheritance be used in perl? Explain with the help of an example.

0 Answers  


what r the different type of function in perl ???

1 Answers   ABC, Symphony,


What's the difference between /^Foo/s and /^Foo/?

0 Answers  


What are the various advantages and disadvantages of perl?

0 Answers  


What does -> symbol indicates in Perl?

0 Answers  


When do you use perl programming?

0 Answers  


Categories