http://www.perlmonks.org?node_id=816177

manishrathi has asked for the wisdom of the Perl Monks concerning the following question:

1)
@trial_array = ("first", "second", "third");


to access second elements of the array, I can use following syntax

$sec_el = $trial_array[1];


now if I am reading in a file datacapture.cgi which has following content
"this is a data file. This ie read in array. this is looped through"
$datafile = datacapture.cgi; open(DAT, $datafile); @data_array = <DAT>;
now each line becomes an element of @data_array. so there are three elements $data_array[0], $data_array[1] and $data_array[2] in @data_array.

if I want to loop through this array using foreach, do I need to use $data_array variabke only or can I use any variable ?
foreach $loopvariable (@data_array) { print $loopvariabe ; }
does it mean that $loopvariable will be assigned the elelments of @data_array one by one ? or do I need to use $data_array[] directly ?

foreach (@data_array)
{ print $data_array ; } #this looks like wrong syntax

2) Do we need to declare array elemnts in double quotes only or can we declare it in single quotes also ? what if array elements are declared without any quotes ? will it be a syntax error ?