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

I know this is not exactly a perl question, but I figured you guys were the fount of all knowledge and would probably be able to help me out. Anyway, the problem: I want to embed some perl code into a ksh script (rewriting the thing in pure perl is not an option at the moment, in that consistency of mediocrity is better than widely varying levels of quality). For example:
#!/bin/ksh USERNAME=`perl <<PERL use MyUtils::Database qw(ReadResource); my %db_info; &ReadResource("\\\$ENV{RCFILE}", "REPORT", \%db_info); print "\\\$db_info{USERNAME}"; PERL` echo "USERNAME is $USERNAME"
The problem is all those unsightly \\\ things to prevent the shell from interpolating the variables. I really hate them in there because I don't want to to confuse people that see that and expect a reference to be taken or something. Has anyone ever dealt with this before? I am looking for a solution that would directly allow perl code out of a perl program and plugged directly into a ksh file.

Replies are listed 'Best First'.
Re: Questions about Calling Perl from a Shell...
by chipmunk (Parson) on Jan 09, 2001 at 02:44 UTC
    I'm afraid I don't have a manpage for ksh. Here's a snippet on here-docs from a bash manpage:
    The format of here-documents is as follows: <<[-]word here-document delimiter No parameter expansion, command substitution, pathname expansion, or arithmetic expansion is performed on word. If any characters in word are quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. Otherwise, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion. In the latter case, the pair \<newline> is ignored, and \ must be used to quote the characters \, $, and `.
    So, if ksh behaves the same way, you can put quotes around PERL and leave off the backslashes:
    #!/bin/ksh USERNAME=`perl <<'PERL' use MyUtils::Database qw(ReadResource); my %db_info; &ReadResource("$ENV{RCFILE}", "REPORT", %db_info); print "$db_info{USERNAME}"; PERL` echo "USERNAME is $USERNAME"
    That approach works for me in bash.
      Yup, single quoting the here.doc tag (i.e. 'PERL') works fine. Thanks.