using subroutine from another file

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default using subroutine from another file

    Let's say thatI wroute some code long time ago:
    code1.pl. In the file there is this subroutine1();

    now I am writting another code code2.pl, and would
    like to use that subroutine1()...how do I do it
    without copy and pasting it to my code2.pl?

    __________________________________
    Do you Yahoo!?
    Yahoo! SiteBuilder - Free, easy-to-use web site design software
    [url]http://sitebuilder.yahoo.com[/url]
    Ling F. Zhang Guest

  2. Similar Questions and Discussions

    1. subroutine problem
      Hi all, I have recently started to learn perl. After reading Randal Schwartz’s Learning perl, I decided to give my first program a whirl. Upon...
    2. Subroutine interaction
      Hi all, the following structure does not work as intended: sub read_index { my $gedicht_path = shift; my (%author_indexlines,...
    3. Who called subroutine.
      Hi, a basic question how do I know who called my subroutine ? It could be main, it could be another subroutine. Is setting a return value on a...
    4. how to trace a subroutine?
      I have a subroutine "foo" in a file "my.pl". I invoke it by: require "my.pl"; &foo; This has worked fine for a while. Now I try to make...
    5. Adding encryption subroutine to file upload script
      I use a Perl file upload script (Powup) but I need to encrypt the files once they reach the server (or before, if there's a way to do that, but they...
  3. #2

    Default RE: using subroutine from another file

    Try this...

    require 'code1.pl';
    call_your_sub();

    This will also execute the code in code1.pl (if there is anything outside of
    a sub block), which may not be what you want.

    Rob


    -----Original Message-----
    From: Ling F. Zhang [mailto:lingfengz@yahoo.com]
    Sent: Monday, September 08, 2003 8:33 PM
    To: [email]beginners@perl.org[/email]
    Subject: using subroutine from another file


    Let's say thatI wroute some code long time ago:
    code1.pl. In the file there is this subroutine1();

    now I am writting another code code2.pl, and would
    like to use that subroutine1()...how do I do it
    without copy and pasting it to my code2.pl?

    __________________________________
    Do you Yahoo!?
    Yahoo! SiteBuilder - Free, easy-to-use web site design software
    [url]http://sitebuilder.yahoo.com[/url]

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    Rob Hanson Guest

  4. #3

    Default Re: using subroutine from another file

    Greetings:

    Well what you wanan do it's export a function from another class.

    You can do it using 2 ways, standard way (using EXPORTER) or
    using Object Oriented Programming in your style.

    learn.perl.org has the Beginning perl book online, check the OO
    chapter and the modules one.

    Good luck!


    On 17:33 Mon 08 Sep , Ling F. Zhang wrote:
    > Let's say thatI wroute some code long time ago:
    > code1.pl. In the file there is this subroutine1();
    >
    > now I am writting another code code2.pl, and would
    > like to use that subroutine1()...how do I do it
    > without copy and pasting it to my code2.pl?
    >
    > __________________________________
    > Do you Yahoo!?
    > Yahoo! SiteBuilder - Free, easy-to-use web site design software
    > [url]http://sitebuilder.yahoo.com[/url]
    >
    > --
    > To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    > For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    --
    Marco Antonio Manzo Bañuelos
    [email]amnesiac@unix-power.net[/email]
    [url]http://www.unix-power.net[/url]

    PGP key 1024D/50C2FDFE 2002-12-20
    fingerprint F90D 93B1 021F 1D35 E57A 9E7F BEEE CE06 50C2 FDFE
    Marco Antonio Manzo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139