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

How to make the following assignment, as arrayreference assignment ? my $arr_ref='[1,2,3,4,4,'elem']';

2 Answers  


How would you trap error occurred in the perl program/file?

3 Answers   IBM,


what are the steps involved in reading a cgi script on the server?

0 Answers  


What is perl? What is the basic command to print a string in perl?

0 Answers  


What are the options that can be used to avoid logic errors in perl?

0 Answers  






What are the advantages and disadvantages of perl language?

0 Answers  


Explain the various characteristics of perl.

0 Answers  


Explain strftime() function in perl?

0 Answers  


What is the function of virtual documents in cgi programs?

0 Answers  


How can you use Perl warnings and what is the importance to use them?

0 Answers  


Write a script for 'count the no.of digits using regular expressions in perl..

6 Answers   AppLabs,


Explain the arguments for perl interpreter.

0 Answers  


Categories