0

In a PHP include, code is parsed as if it was written right into the source file. You get the same result as if you literally copy and pasted file A into file B.

I'm looking for a way to do this in Perl. The number of libraries I have to 'use' in every script is getting annoyingly large, and especially annoying is having to use v5.14 just so I can have the say function. I'm actually looking up how to alter the interpreter to always use the latest version of Perl at this moment, compatibility with the rest of the world be damned, but this won't solve the rest of my list of includes.

Edit: none of the linked answers answer the question.

felwithe
  • 2,683
  • 2
  • 23
  • 38
  • `use feature qw(say)` will also enable the say function. I am curious what you are doing that is generating a list of use statements that is too much to manage. – Hunter McMillen Aug 03 '15 at 15:27
  • 1
    More info here also: [How can I export a list of modules with my own module?](http://stackoverflow.com/questions/30814892/how-can-i-export-a-list-of-modules-with-my-own-module) – Håkon Hægland Aug 03 '15 at 15:46

1 Answers1

3

The equivalent of PHP's include is do EXPR. There is also require EXPR, which is like require_once, and use, which will also call import on the package.

However that is probably not what you want. If you have a lot of .pl scripts without packages, you are dealing with legacy code. You need to be carefull what you require and include where.

simbabque
  • 53,749
  • 8
  • 73
  • 136
  • `do` doesn't apply its use statements to the calling script; I did try that first. – felwithe Aug 03 '15 at 16:05
  • To clarify: If my file contains "use v5.14", I include it with "do", then try to "say" something, I'll get an error that say is not a function. – felwithe Aug 03 '15 at 16:15
  • You can `import` the `feature` pragma from another file. That way you can get all your pragmas from one file, cutting down boilerplate. – simbabque Aug 03 '15 at 16:31