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

Why to use perl?

0 Answers  


What is “grep” function in perl?

0 Answers  


We all know private variables exist in perl. But do private METHODS exist in perl ? Eg ?

0 Answers   AppLabs,


List the operator used in Perl?

0 Answers  


Explain the difference between die and exit in perl?

0 Answers  


How to find the length of an array in perl?

0 Answers  


How to copy a file in perl?

0 Answers  


write a script to generate n prime no.s?

2 Answers   Persistent,


Why should I use the -w argument with my Perl programs?

0 Answers  


How do I send e-mail from a Perl/CGI program on a Unix system?

0 Answers  


Why we use "use lib $path"?

1 Answers  


How can you replace the characters from a string and save the number of replacements?

0 Answers  


Categories