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 ?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.