Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem with using two conflicting CPAN modules which I don't know how to solve. Both of the modules in question make use of a select function and I'd really like to use them within the same subroutine.
Here's some code that demonstrates the problem
use Shell::POSIX::Select qw($Heading $Prompt); use Config::Crontab; $modcron = 1; if (defined($modcron)) { modifycron(); exit; } sub modifycron { $Heading="\n Pick an Option\n\n"; $Prompt="Enter selection: "; select ('Display','Activate') { if ( $Reply == 1 ) { $ct = new Config::Crontab; $ct->read; print $ct->dump; } elsif ($Reply == 2) { $ct = new Config::Crontab; $ct->read; $block = $ct->block($ct->select(-command_re => "key="); } }
The test crontab looks like this
# # Host specific jobs #################### # #00 8 * * * $MYBIN/my_prog.pl; # key=my_prog #00 9 * * * $MYBIN/my_prog2.pl; # key=my_prog2
Running this gives me
syntax error at ./test.pl line 151, near ");" Missing right curly or square bracket at ./test.pl line 186, at end of + line syntax error at ./test.pl line 186, at EOF Execution of ./test.pl aborted due to compilation errors.
I'm trying to build a (ksh style select) menu around the crontab module
Can I make use of these two modules in the same script ?
If so how ?
Any help appreciated

Replies are listed 'Best First'.
Re: Conflicting modules
by rafl (Friar) on Mar 14, 2006 at 11:41 UTC

    Usually it's not a problem to use two modules that both export a sub with the same name.

    For example you could simply load one of the modules without importing anything:

    use Foo ();

    Afterwards you can still use the select function in Foo.pm by calling

    Foo::select();

    If you want to have the function imported into your namespace you can still do that, but not using the same name.

    In this specific case I don't think the problem (a syntax error) is caused by the fact that two modules have a sub with the same name. Unfortunately the error message you posted doesn't seem to come from the script your showed. The error is refering to line 151 and 186. The script you posted doesn't have that much lines so it's difficult to find out what caused the problem. Maybe you can provide the full script?

    Cheers, Flo

Re: Conflicting modules
by izut (Chaplain) on Mar 14, 2006 at 12:38 UTC

    You're missing the closing parenthesis here:

    $block = $ct->block($ct->select(-command_re => "key=");

    It should be:

    $block = $ct->block($ct->select(-command_re => "key="));

    Igor 'izut' Sutton
    your code, your rules.

      Hmm. Thanks. I should have spotted that one !