in reply to Learn Unix multiline syntax

Remember that the “multi-line syntax” of the shell is simply a cue to the shell that it should not execute the current input immediately, but should instead prompt for another line of input.   The shell removes the trailing backslash from each line before processing the concatenated remainder.

In Perl, you will simply create a string variable containing the entire command that you wish to execute.   This string should not contain “continuation characters.”   If the string needs to contain any special characters, remember that they might need to be properly “escaped.”

Finally, remember how Perl treats string literals that are enclosed with double quotes differently from those that are enclosed with single quotes.   Double-quoted strings are interpolated, which means that Perl looks for things that appear to be variable-references in such strings, and attempts to replace them with the value of the corresponding variable.

A good, practical approach is to first simply print the string to STDERR, to see if it is correct.   Stop coding at that point, and make corrections as necessary.   When all is well, proceed to finish the program.

Replies are listed 'Best First'.
Re^2: Learn Unix multiline syntax
by locked_user sundialsvc4 (Abbot) on Aug 16, 2010 at 22:22 UTC

    To clarify:   the shell has its own way of handling “$whatever”:  it substitutes an environment-variable.   But if you are assembling a double-quoted string, and perhaps in other situations also, “Perl gets there first,” and substitutes a Perl variable (or nothing).   There are various ways to avoid this behavior, including the use of \$ (which means, “the literal character, ‘$’”).   Hence, I stand by the admonition to “first, just print it out.”   It is a (very easy!) waste of time to try to figure out why a string is not being interpreted correctly, only to discover (too late!) that the string does not actually contain what you thought it would.

    (Let’s ask the Peanut Gallery here:    Will everyone who has done exactly this, please raise your hands?”   :-D   I rest my case.   (And lower my hand.)