[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-WebCGI] 2 Basic loop question(?)



Well, I'm probably just as much a beginner; but I would do it this way:

	@myArray = split(/\t/, $_);	# read them into a straight array
	for ($row=0;$row<25;$row++) {
		for ($col=0;$col<30;$col++){
			@realarray[$row][$col] = $myarray[$row*30+$col];	# convert to row/col array	
# or in here just plop your html if you are displaying to the web
			print "<td>$myarray[$row*30+$col]</td>\n";
		}
	}

Riccardo Perotti wrote:
> 
> Hi all:
> 
> I'm a Perl beginner trying to do something with I guess is pathetically
> basic but I haven't been able to work out.
> 
> I'm opening a tag delimited file which contains a data base (ie: 25 rows x
> 30 cols). In order to be able to refer to each 'cell' in the data base (ie:
> $c7 = 3rd row, 7th column'), I'm doing:
> 
> open(INF,"data.txt") or die() ;
> @datos = <INF>;
> close(INF);
> chomp(@datos );        #    ...then...:
> 
> $a = $datos[0];
> $b = $datos[1];
> $c = $datos[2];
> $d = $datos[3];
> .... (all the way to)...
> $z = $datos[25];         #         !!!!, .... and then...:
> 
> ($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12, $a13, $a14,
> $a15, $a16, $a17, $a18, $a19, $a20, $a21, $a22, $a23, $a24, $a25, $a26,
> $a27, $a28, $a29, $a30) = split(/\t/,$a);
> ....(all the way to)...
> ($z1, $z2, $z3, $z4, $z5, $z6, $z7, $z8, $z9, $z10, $z11, $z12, $z13, $z14,
> $z15, $z16, $z17, $z18, $z19, $z20, $z21, $z22, $z23, $z24, $z25, $z26,
> $z27, $z28, $z29, $z30) = split(/\t/,$z);   # !!!!!!!!
> 
> Now, though clumsy, it *does* work, but I'm sure there's a more proper way
> to do it using loops, aside from the fact that it wouldn't be very practical
> to write for a 300 row x 300 column data sheet!
> 
> I've been trying to figure these loops out, but have "failed with all
> success".
> 
> Can somebody *please* give me a hand with better alternatives, be them loops
> or some kind of shortcut?
> 
> Thank you,
> 
> Riccardo Perotti
> 
> --
> mailto:perotti@pobox.com
> 
> ==== Want to unsubscribe from this list?
> ==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org

-- 

-- In Light and Love
EaTrom
Order of Melchizedek
Michael's Legions
----------------------------------------------------------------------------
EaTrom's Site:&nbsp; http://www.blazing-trails.com Spirituality & Conspiracy
----------------------------------------------------------------------------

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org