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, 9:43 AM


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

Hi,

Make sure you reference each write function when constructing the dispatch func hash, you are currenly calling each write function instead, which will likely have returned an undef value:


Code
my %dispatch_func;  
$dispatch_func{FILE1} = \&write_to_file1;
$dispatch_func{FILE2} = \&write_to_file2;
$dispatch_func{FILE3} = \&write_to_file3;
$dispatch_func{FILE4} = \&write_to_file4;


Better yet, extend the input hash instead:


Code
FILE1 =>   
{
path => $ARGV[0],
delim => '|',
headings => [],
dispatch_func => \&write_to_file1,
},

...

my $dispatch_func = $worksheet_info->{dispatch_func};
$dispatch_func->( \@data, $myid );


And finally, make sure you declare subroutines using sub and that you use or assign the arguments from @_ appropriately:


Code
sub write_to_file1  
{
my ( $data, $myid ) = @_;

for my $col ( 0 .. $#{$data} )

...


Regards,

Chris


(This post was edited by Zhris on Dec 15, 2014, 9:52 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Dec 15, 2014, 9:49 AM
Post edited by Zhris (Enthusiast) on Dec 15, 2014, 9:52 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