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 various uses of perl?

708


How many types of primary data structures in Perl and what do they mean?

1062


What are the purpose of close(), getc() and read() functions?

644


How to implement a stack in Perl?

760


What are the functions that can be performed using cgi program?

661


Which functions in perl allows you to include a module file.

660


Explain goto expr?

642


What is stdin in perl?

721


What is perl pop array function?

699


What does init 5 and init 0 do?

712


What is a perl references?

674


How the interpreter is used in Perl?

709


Explain the execution of a program in perl.

681


What does the’$_’ symbol mean?

758


How to dereference a reference?

741