> 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.
It's a dereference. In other words, if $line is a reference to an array,
then @$line retrieves the original array. You can also write it @{$line} if
it's easier for you to understand.
- Mark.
P.S. The plural of matrix is matrices, not "matrix's"
> -----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
>
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs