G'day rkeshvardoost,

You have some questionable code here. Consider these two adjacent lines:

package R; package R::startR;

Are you missing some code that should come after package R;? If not, why did you use package R; in the first place?

The use lib 'R'; line seems to be in the wrong place in your code. Without knowing your directory structure, I can't even say if it's correct (regardless of its position).

In this part of your code:

package R::startR; ... @EXPORT_OK = qw(startR ...

that refers to R::startR::startR. Was that what you meant? If so, you haven't declared it!

At this point, I'm starting to have to make many guesses as to your actual intent. The following is how I might have written something that may be close to what you want.

Firstly, I created a directory (pm_1152700_libs) and populated it like this:

$ cat pm_1152700_libs/R.pm package R; use Exporter 'import'; our @EXPORT_OK = qw{startR}; sub startR { print 'This is &R::startR' } 1;
$ cat pm_1152700_libs/R/startR.pm package R::startR; use Exporter 'import'; our @EXPORT_OK = qw{startR}; sub startR { print 'This is &R::startR::startR' } 1;

I then wrote this test script (but do see the notes I've written afterwards):

#!/usr/bin/env perl -l use strict; use warnings; use lib 'pm_1152700_libs'; use R qw{startR}; use R::startR qw{startR}; R::startR(); R::startR::startR();

which outputs

This is &R::startR This is &R::startR::startR

You've used startR in both module and subroutine names. This is highly error-prone and I'd recommend you think of better names.

I've repeated the use of startR in both module and subroutine names; however, note the following:

Finally, I strongly advise that you use the strict and warnings pragmata at the start of all your scripts.

— Ken


In reply to Re: Undefined subroutine error while using R within Perl by kcott
in thread Undefined subroutine error while using R within Perl by rkeshvardoost

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.