1) For some information about this from the documentation, see For Loops and Foreach Loops in perlsyn. The short of it is you can define your own loop variable if you like, or not define it and have your elements assigned to the magic variable $_. Like this:

foreach my $loop_variable (@data_array) { print $loop_variable; }

or this:

foreach (@data_array) { print $_; }

As a side note, see how all your array elements are links? That is because you did not wrap your code in <code> tags. See Writeup Formatting Tips.

2) You are not declaring array elements so much as defining strings and storing those in your array. Your syntax will work so long as you have a comma separated list of strings. That means you can use pairs of single quotes, pairs of double quotes or any of a host of delimiters listed in Quote and Quote like Operators. For your case, you may be particularly interested in the qw() delimiter, since that uses whitespace to delimit your strings instead of commas.


In reply to Re: looping through array by kennethk
in thread looping through array by manishrathi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.