Hello Lady Aleena

Maybe you want to use the sub that you eventually create to be used by several programs...

There is a technique that I sometimes use to be able to use common functionality that is needed by several programs. And I don't want to repeat myself over and over so I put those in libraries that are commonly accessible. E.g. I have a simple "CommonFunctions.pm" file containing functions like "trim", "trimleft", "trimright". I will share this example how to achieve this because I think it might be usefull to you. I have added use examples below under __END__.

MySVG.pm

package MySVG ; use strict ; use warnings ; use Exporter ; use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS ) ; @ISA = qw( Exporter ); @EXPORT = ( ) ; @EXPORT_OK = qw( gen_y family_y ) ; %EXPORT_TAGS = ( SVGFunc => [qw( &gen_y &family_y )] ) ; sub gen_y { my $gen = shift; my $multiplier = $gen - 1; my $gen_y = 36 + ( 76 * $multiplier); return $gen_y; } sub family_y { my ($gen, $two_parents, $one_parent) = @_; my $multiplier = $gen - 1; my $modifier = $two_parents ? 0 : $one_parent ? 18 : 38; my $family_y = (-18 + (-76 * $multiplier)) + $modifier; return $family_y; } 1; __END__ use examples (which should always work in case MySVG is in the same lo +cation as your program): - use MySVG qw( :SVGFunc ) ; - use MySVG qw( gen_y ) ; Ways to make perl find the lib in case it is somewhere else: - Add location of MySVG to PATH environment variable - use the perl -Idirectory switch - In case only your current project uses it and the pm file is in say +"lib\MySVG\" and you are working on a file in lib\somewhere-else\: use File::Basename qw( dirname ) ; use lib dirname( dirname __FILE__ ) . '/MySVG' ;

In reply to Re: Get code ready for a loop (and a little RFC) by Veltro
in thread Get code ready for a loop (and a little RFC) by Lady_Aleena

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.