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

How will you access an element of a perl array?

0 Answers  


Does Perl have objects? If yes, then does it force you to use objects? If no, then why?

0 Answers  


What?s your favorite module and why?

3 Answers  


How can arrays be tied?

0 Answers  


You want to download the contents of a url with perl. How would you do that?

0 Answers  






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

3 Answers   IBM,


How can you create anonymous subroutines?

0 Answers  


What is the difference between module and package?

4 Answers   EDS, IBM, Symantec,


What is the difference between having a parenthesis after module name and without parenthsis after module name?? i.e Package::Module(); and Package::Module;

1 Answers  


Explain grooving and shortening of arrays and splicing of arrays?

0 Answers  


Mention the difference between die and exit in Perl?

0 Answers  


How to read a file into a hash array?

0 Answers  


Categories