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 is lexical variable in perl?

520


Which operator in perl is used for the concatenation of two strings?

492


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

545


What does undef function in perl?

521


Which has highest precedence in between list and terms? Explain?

438






How to implement a stack in Perl?

578


Where the command line arguments are stored and if you want to read command-line arguments with Perl, how would you do that?

687


Why -w argument is used with perl programs?

554


What is perl? What is the basic command to print a string in perl?

480


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

515


Explain chomp, chop, cpan, tk.

530


Difference between the variables in which chomp function work ?

604


How will you open a file in read-only mode in perl?

506


How does polymorphism work in perl? Give an example.

479


What is perl scripting?

512