I'm not very good at Perl (yet, i hope) and i was wondering if there's a way to create a sub that behaves like a built-in function.

This is my situation:

I have a module "global" in which a sub "compress" is defined. I use this module from the main package, and my program calls other modules at runtime. Is there a way to make the "compress" behave like a built-in function so that i don't have to use the "global" module from the called modules?

It uses different files:

- GLOBAL.pm: in which the compress sub is stored - script.pl: the main script - module_a.pm: some random module which uses compress - module_b.pm: etc.

I guess i have to use the Exporter module in some way, but that only seems to let a package that uses the "global" module.

Is this a 'correct' way to program or is it morally wrong and should i just use "GLOBAL->compress" instead of trying to call it with "compress" each time?

Thanks in advance! ;]

In reply to Create a built-in-like sub? by mirg drol

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.