The nearest perl equivalent to "sourcing" in shell is
do. In shell, "sourcing" is different from executing... that is: when you execute a program (whether another shell script or a binary executable or whatever) it executes in a separate process, with it's own environment and variables and so on. When you source another shell script (you can only source other shell scripts, you cannot source a binary executable) it is just treated as though the code were dropped right into your shell (or shell script) right there. Thus, any changes to the shell's environment and variables and so on which are made by the source-ee take effect in the source-or (big difference from when another command is executed in a subprocess/subshell).
Anyways, likewise in perl. You can execute any arbitrary command (a shell script, perl script, binary executable, whatever... see perldoc -f system), but it will occur in its own subprocess. You can also "source" a file full of other perl code directly into your perl script, affecting your scripts environment, variables, and so on. You do that like:
do "script_name.pl";
just like you would say:
source script_name.sh
or (the same thing)
. script_name.sh
(the . is just a shortcut for writing the command "source" in shell). There are some minor differences between perl's "do" and shell's "source". The biggest difference is probably that perl's "do" will return the last value computed in the called script. For more info, check out
perldoc -f do.
------------
:Wq
Not an editor command: Wq
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.