Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to print a shell script enbedded in a perl script to a file. Is there a way to print the block of code without it being interpolated?

Replies are listed 'Best First'.
Re: Printing Code
by impossiblerobot (Deacon) on Jan 25, 2002 at 09:41 UTC
    I would probably use a here-doc with single quotes:
    open(FILE, ">test.sh") or die "Couldn't open test.sh."; print FILE <<'EOS'; #!/usr/bin/sh echo 'This is a test' EOS close(FILE); print "File written";
    In Perl, you can prevent the contents of a string from being interpolated by quoting it with single quotes, or using the q// quote-like operator. See perlop (Quote and Quote-like Operators) and perldata (here-doc).

    Impossible Robot
Re: Printing Code
by belg4mit (Prior) on Jan 25, 2002 at 09:41 UTC
    Yes, try some form of non-interpolating quoting. Searching ought to come with some useful hits in the man pages.

    --
    perl -pe "s/\b;([st])/'\1/mg"