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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |