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 are the logical operators used for small scale operations?

0 Answers  


How to copy a file in perl?

0 Answers  


What does file test operators do in perl?

0 Answers  


What elements of the Perl language could you use to structure your code to allow for maximum re-use and maximum readability?

1 Answers  


There are two types of eval statements i.e. Eval expr and eval block. Explain them.

0 Answers  


Which guidelines by Perl modules must be followed?

0 Answers  


What are the advantages of perl programming?

0 Answers  


What is qq (double q)operator in perl?

0 Answers  


Write a script to reverse a string without using perl's built in functions?

0 Answers  


What $! In perl?

0 Answers  


What does read () command do?

0 Answers  


Categories