this explained just about everything and was 10 times less confusing than my own broken code. where I really get confused in Perl is different situations will return ARRAY reference and others will return the element.
as an example (printf is obviously better), if i were to do a print @$line . "\n" it will return a number so I dont know why that is so. also the @$line is confusing to me since I thought @ implied a whole array thus meaning an array reference so I cant seem to explain how @$ works. -----Original Message----- From: Bruce Hudson [mailto:[EMAIL PROTECTED] Sent: Thursday, February 05, 2004 2:04 PM To: [EMAIL PROTECTED] Subject: Re: [Perl-unix-users] need help with matrix's You do not really explain what you need help with. Let me try a quick rewrite of your code so it looks a bit less like C and maybe you can ask specific questions. This is untested code so you may have to play with it a bit. -- Bruce A. Hudson | [EMAIL PROTECTED] UCIS, Networks and Systems | Dalhousie University | Halifax, Nova Scotia, Canada | (902) 494-3405 use strict; use warnings; my @newmatrix=( ["123.45" , "JOHN DOE" , "Coal Miner" ] , ["12.45" , "MR. PEANUT" , "peanut" ] , ["4.1" , "Bill Clinton" , "unknown" ] ); my @maxlength; foreach my $line (@newmatrix) { my $index = 0; foreach my $column (@$line) { $maxlength[$index] = 0 unless (defined $maxlength[$index]); if ((length $column) > $maxlength[$index]) { $maxlength[$index] = (length $column); } $index++; } } my $format = ""; foreach my $width (@maxlength) { $format .= " " if ($format); $format .= "%-" . $width . "s"; } foreach my $line (@newmatrix) { printf "$format\n", @$line; } _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs