I have a package with the following contents.
-------------------
package abhinav::test;

use strict;
use warnings;

sub test1
{
        return "\nHello World";
}

sub test2
{
        my ($include) = @_;
        foreach my $row (@$include)
                {
                push (@$row, @$row[0] + 10);
                }
        return $include;
}

1;
-------------------



Now, The thing I am trying to achieve is to call abhinav::test::test2
on the runtime.
ie, I am passing the value 'abhinav::test::test2' in a variable, and
trying to exec in the code below, and this place I am failing.
Can someone help me as to how to achieve this in runtime.
Thanks
-------------------
use strict;
use abhinav::test;

my @arr = (['1','2'], ['3','4'], ['5','6'], ['7','8']);

print("\n --- ORIGINAL ARRAY ---\n");
foreach my $row (@arr) {
        print(@$row);
        print "\n";
}

print("\n --- THIS IS A STATIC CALL ---\n");
my $arr = abhinav::test::test2([EMAIL PROTECTED]);
foreach my $row (@$arr) {
        print(@$row);
        print "\n";
}


print("\n --- THIS IS A DYNAMIC CALL ---\n");
my $dyna_sub = 'abhinav::test::test2';
my @arr = (['1','2'], ['3','4'], ['5','6'], ['7','8']);
my $sub_str = $dyna_sub . '(' . [EMAIL PROTECTED] . ')';
my $arr = eval $sub_str;
print ("\n -- ERRR -- $@ --\n");

foreach my $row (@$arr) {
        print(@$row);
        print "\n";
}

-------------------

-----------------------------------------
Output of the above is as:
 --- ORIGINAL ARRAY ---
12
34
56
78

 --- THIS IS A STATIC CALL ---
1211
3413
5615
7817

 --- THIS IS A DYNAMIC CALL ---

 -- ERRR -- Undefined subroutine &main::ARRAY called at (eval 1) line
1.
 --
-----------------------------------------


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


Reply via email to