Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Like it or not, modules are the best way. Modules need not be difficult; you probably need only a small fraction of the many options available to a module author. To get started, see tachyon's Simple Module Tutorial, including the other monks' comments at the bottom. If the tutorial is too simple, try perlman:perlmod. If too complex, try my skeleton code below. I have pared it down to the bare essentials for illustration only; it runs correctly, but is missing the seat-belts (use strict) and air-bags (use warnings), so don't take it out of the parking lot!

Use h2xs -n Common_Code -AX to generate a real module template once you are more comfortable with how a module works.

# this is in file Common_Code.pm package Common_Code; sub log_debug_message { print "DEBUG: I see ", join(", ", @_), ".\n"; } 1;
Here's a script which uses it:
#!/usr/bin/perl use Common_Code; my( $a1, $b2, $c3 ) = qw( red blue green ); Common_Code::log_debug_message( $a1, $b2, $c3 );
The output:
DEBUG: I see red, blue, green.

In reply to Re: What's the best way to share code in different files? by Util
in thread What's the best way to share code in different files? by aeshirey

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found