CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Tejas] How to write dispatch tables ? How to send arguements to the functions : Edit Log



Zhris
Enthusiast

Dec 15, 2014, 10:42 AM


Views: 30481
Re: [Tejas] How to write dispatch tables ? How to send arguements to the functions

Hi,

One approach could be to supply the col numbers of your string and date cols in your input hash. You can pass these col numbers when you call the dispatch function.


Code
FILE1 =>    
{
path => $ARGV[0],
delim => '|',
headings => [],
cols => { string => [ 1, 12 ], date => [ 2, 3, 11 ] },
},



Code
use List::Util qw/ any /; 

...

write_to_file( ..., $worksheet_info->{cols} );

...

sub write_to_file
{
my ( $data, ..., $cols ) = @_;

for my $col ( 0 .. $#{$data} )
{
if ( any { $col == $_ } @{$cols->{string}} )
{
$worksheet->write_string( $row, $col, $data[$col] );
}
elsif( any { $col == $_ } @{$cols->{date}} )
{
$worksheet->write_string( $row, $col, $data[$col], $date_format );
}
else
{
$worksheet->write_number( $row, $col, $data[$col] );
}
}
}


Regards,

Chris


(This post was edited by Zhris on Dec 15, 2014, 10:43 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Dec 15, 2014, 10:43 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives