Subject:                Simplification of the code
Date sent:              Tue, 22 May 2007 19:04:01 +0530
From:                   "Nath, Alok (STSD)" <[EMAIL PROTECTED]>
To:                     <beginners@perl.org>

> Hi,
>       Can anybody help me to simplify the for loops here ?
>       It parses the excel file.
>       
> 
>       foreach my $col (1..10){
>               push @row_1, $Sheet->Cells(1, $col)->{'Value'} ;        
>       }
>       my @node_names = th([EMAIL PROTECTED]);

Why the @row_1 variable?

        my @node_names;
        foreach my $col (1..10){
                push @node_names, $Sheet->Cells(1, $col)->{'Value'} ;   
        }
        @node_names = th(\node_names);

or even better

  my @node_names = th [map { $Sheet->Cells(1, $_)->{'Value'} } 
(1..10)];


>       foreach my $col (1..10){
>               push @row_2, $Sheet->Cells(2, $col)->{'Value'} ;        
>       }
>       my @workstations = td([EMAIL PROTECTED]);
> 
> 
>       foreach my $col (1..10){
>               push @row_3, $Sheet->Cells(3, $col)->{'Value'} ;        
>       }
>       my @cards = td([EMAIL PROTECTED]);


The different functions make it a bit harder, but you could merge 
those loops into this:

  my @rows = map {
    my $row = $_;
    [ map { $Sheet->Cells( $row, $_)->{'Value'} } (1..10) ]
 } (1..3);

to get the data and then

>       I am using the above for loops to create a table -finally.
> 
> 
>       print table({-border=>undef,-width=>'100%'},
>             caption(b('My table')),
>             Tr([EMAIL PROTECTED]),
>             Tr([EMAIL PROTECTED]),
>             Tr([EMAIL PROTECTED]),
>       }

        print table({-border=>undef,-width=>'100%'},
             caption(b('My table')),
             Tr([ th $rows[0]]),
             Tr([ td $rows[1]]),
             Tr([ td $rows[2]]),
        }

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


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


Reply via email to