Paul Kraus wrote:
>
> This is a simple bit of code that scans through a file and determines the
> width setting for columns that will eventually be written out using
> spreadsheet::writexcel.  It works fine but I am curious if there is a way to
> do it with map or grep that would be better? This is more for learning the
> practicality. Thanks.
>
> my $count = 0;
>     foreach ( @record ) {
>       my $length = length( $_ );
>       $widths[ $count ] = $length if ( $widths[ $count ] < $length );
>       $count++;
>       push ( @sheet, [ @record ] );
>     }

No. Sadly. If only 'each' would work on an array then you'd be in
business, but you're trying to maintain two parallel arrays: @record and
@widths. Perl requiers that you have an artificial index, $count, that
is there only for the compiler's sake.

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to