#!/usr/bin/perl use warnings; use strict; use POE; my $up_bound = 10; my $final_result = parallel_with_poe($up_bound); sub parallel_with_poe { $ubound = shift; POE::Session->create( inline_states => { # How can I pass the parameter correctly here? _start => Function_1($_KERNEL,$ubound); to_wait => sub { $_[KERNEL]->(delay (tick=>2)); } run_function_2 => Function_2($_KERNEL,$ubound); # This ain't right also, I don't know # how to pass the above result into the function _stop => final_sum($_KERNEL,$ubound); }, ); $poe_kernel->run(); return; # how to return the final value? #exit(0); } sub final_sum { my ($kernel,$ans_of_f1, $ans_of_f2) = @_; my $sum = $ans_of_f1+$ans_of_f2; return $sum; } sub Function_1 { my ($kernel_f1, $up_bound1) = @_; my $total_f1; foreach my $in ( 0 .. $up_bound1) { $total_f1 += $in/3; } return $total_f1; } sub Function_2 { my ($kernel_2,$up_bound2) = @_; my $total_f2; foreach my $in (0 .. $up_bound2) { $total_f2 += $in; } return $total_f2;