Since you claim to be new (like me), some comments on your code:

my $i=""; my $t=""; my @data="";

Variables that have never been used have the special undef value. What happens if you use a variable that has the undef value? Nothing serious

If you use it as a number it takes on the value 0 (zero). If you use it as a string it takes on the value of an empty string. You do not have to set them to "". You use $i and $t as numeric values in your code so setting them to "" is kinda confusing.

Setting the array @data to "" does not make much sense for an array either. If you want to empty an array assign it to an empty list:

my @data = ();

But a new array starts out this way anyway.

Now lets take a look at your loops...

$lines=scalar@data/4; for ($t=1; $t<=$lines; $t++) { for ($i=1; $i<=4; $i++) { $items=shift(@data); print $items; }

($t=1; $t<=$lines; $t++) works, but it is more common to start with $t=0 and use $t<$lines as the termination.

Getting used to this will prevent you from getting into trouble when indexing through arrays which start with an index of zero. It also prevents a finger-flub of forgetting the = in the condition.


Lou

Update: Oh, one more thing that is good to get used to when you are new. Besides using use strict;, also consider...

use warnings; # flags many questionable constructs use diagnostics; # makes error messages much more understandable

Lou


In reply to Re: Array manipulation by TheStudent
in thread Array manipulation by loop362

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.