Berkeley CSUA MOTD:Entry 14605
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

1998/9/15-16 [Computer/SW/Languages/Perl] UID:14605 Activity:insanely high
9/15    Is there any way in Perl to do the same is #include in C?  That is,
        just insert the text of one file into another?
        \_ if you mean to include or share perl libraries,
           the "require" keyword will work in most cases.
           perl5 has more powerful module support with "use".
           \_ No, I have one big script that parses input, and would like to
              use it in another to parse and do some other stuff.
              Basically, I have file1.pl, and would like to do
              #include "file1.pl"
              sub_defined_in_file1();
              \_ he answered your question, idiot.
                 \_ No he didn't. I've read the docs on require and use,
                    and it isn't working.  I'm not trying to include perl
                    libraries.
                    \_ require is what you want.  your fu is weak.
                       train harder.
                        \_ require "included.pl" returns:
                included.pl did not return a true value at test.pl line 2
                        Since I was specifically looking for something as
                        simple as #include, it appears that require won't
                        do the job.  I don't want to go through the hassle
                        of creating a module if I don't have to.  A simpler
                        answer to the first question would have been, "No,
                        there is no equivalent of #include in perl.  You
                        have to create a module."
                        \_ No you don't have to create a module, just make the
                           last line of the file you require be: "1;" which
                           will evaluate to the true value perl is looking for
                           \_ Thank you!
                                \_ You obviously didn't RTFM.
                    \_ Yes.  He did.  Indeed your fu is not weak.  You lack
                       all traces of fu.
                       \_ My kung fu is the best. -billg
                                \_ Everyone was kung fu fighting -discoman
        \_ Why yes indeed. Perl needs to run with the -P flag. That can go in
                 Also read the man pages on use and require -- there are
                 some subtle differences (among other things, require
                 does "run -time" inclusion, and use does "compile-time"
                 inclusion.
           in the shbang line (e.g. "#!/path/to/perl -w -P"). man perlrun
           for more details. -anirvan
        \_ Summary of require solution:
           require "include.pl";
           the last expression in include.pl must evaluate to true
           (non-zero)
           \_ i.e. make the last line:
              1;
           \_ Read about the AUTOLOAD method in the perlsub manpage.
              Also read the man pages on use and require -- there are some
              subtle differences (among other things, require does "run
              -time" inclusion, and use does "compile-time" inclusion.