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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different string manipulation operators in perl?

536


Define perl scripting?

581


What is perl push array function?

551


What is the purpose of _package_ literal?

542


What is the easiest way to download the contents of a URL with Perl?

566






Explain goto name?

530


Why to use perl?

543


What is the main function of cookie server?

531


Who created perl?

534


How to connect to SQL server through Perl?

570


Comment on array slicing and range operator

529


What does delete function do in perl?

524


Which guidelines by Perl modules must be followed?

573


How to access parameters passed to a subroutine in perl?

545


Explain lexical variables.

525