I've asked this before but I think I'm having a hard time being clear. Or this is somehow beyond my head. I have a subroutine that I want to define in module Fruit.pm. Fruit.pm exports this sub first to the main calling program, makesalad.cgi.
Fruit.pm also calls

i have Fruit.pm, Apple.pm, makesalad.cgi

package Fruit; use vars qw{$VERSION @ISA @EXPORT @EXPORT_OK}; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(slice slice_some); use strict; sub slice; # so i don't have to call slice() - is this the right place + to do this ? sub slice_some; sub slice_some { slice 'grapefruit'; slice 'straberries'; } sub slice { my $thing = $_[0]; defined $thing or $thing = 'default_thing'; # slice here.. } 1;
package Fruit::Apple; use vars qw{$VERSION @ISA @EXPORT @EXPORT_OK}; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(cut); use strict; use Fruit; sub cut; sub cut { my $thing = $_[0]; defined $thing or $thing = 'default_thing'; # cut here.. and then also use slice... slice 'mango'; slice; } 1;
#!/usr/bin/perl -Tw # this is makesalad.cgi use strict; use Fruit; use Fruit::Apple; slice_some; slice 'orange'; slice; cut; exit;

the subroutine slice is being accessed by all three parts of the program- but the subroutine slice is only accessible to makesalad.cgi and Fruit.cgi, not to Apple.cgi even though it also makes use of Fruit.pm.. The only way to call slice properly in Apple.pm is to do this : ::slice(); - why?? Is it because *use* only runs once therefore slice is only accessible to main? What is going on here? is it because use is a one time pre compile thing, should I use require for Fruit.pm on both makesalad.cgi and Apple.pm ? Ouch.. Help .. ouch..


In reply to making a subroutine export into the main script and also to other modules by leocharre

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.