What is the difference between $array[1] and @array[1]?



What is the difference between $array[1] and @array[1]?..

Answer / kiruthikau

$array[1] represents a scalar value.
@array[1] represents array slicing.

@array[1] returns a list with one scalar value.

We should use $ when we want a scalar value.
If we want a list we need to use @.

If we use 'use warnings' then @array[1] will give the warnings
like ,Scalar value @array[1] better written as $array[1].

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More CGI Perl Interview Questions

Explain goto name?

0 Answers  


What package you use to create a windows services?

0 Answers  


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

0 Answers  


What is the peculiarity of returning values by subroutines in perl?

0 Answers  


Why to use perl?

0 Answers  


What is the importance of perl warnings?

0 Answers  


What does the’$_’ symbol mean?

0 Answers  


If you want to empty an array then how would you do that?

0 Answers  


What are some of the key features of objects in perl?

0 Answers  


How can the user execute a long command repeatedly without typing it again and again?

0 Answers  


How do I sort a hash by the hash key?

0 Answers  


Why is it hard to call this function: sub y { "because" } ?

0 Answers  


Categories