in reply to "do" command versus "source" in bash
That's why I like using code from other files.
Code reuse is a Good Thing. The way this is usually done in Perl is with modules.
TIMTOWTDI but one example using Exporter is shown here to get you started. Here is a module MyPaths.pm which I have just written:
use strict; use warnings; package MyPaths; use parent 'Exporter'; our @EXPORT_OK = qw/$pathfoo $pathbar/; our $pathfoo = '/path/foo'; our $pathbar = '/otherpath/bar'; 1;
And here is importtest.pl which makes use of that module:
#!/usr/bin/env perl use strict; use warnings; use lib '.'; use MyPaths '/path/'; print "paths are $pathfoo and $pathbar\n";
The use statement will import any exportable symbols from the module which match the regular expression. When we run importtest.pl we see this:
$ ./importtest.pl paths are /path/foo and /otherpath/bar $
There is a lot more to modules and exporting/importing than this but it shows you how to get going with the basics.
🦛
|
|---|