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


Please Help Members By Posting Answers For Below Questions

Is perl compiler or interpreter?

540


How we can navigate the xml documents?

535


What can be done for efficient parameter passing in perl? Explain.

562


What are the steps involved in configuring a server using cgi programming?

481


Write syntax to use grep function?

550






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

487


Difference between the variables in which chomp function work ?

608


You want to connect to sql server through perl. How would you do that?

541


Explain the functioning of conditional structures in perl.

469


Why do you use Perl?

547


Explain socket programming in perl?

512


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

511


What does the qq{ } operator do?

553


How to implement a stack in Perl?

584


What happens in dereferencing?

538