in reply to Using <<EOL > output.out and EOL

See the discussion of  <<EOF (a here-document or here-doc) in the Quote and Quote like Operators section and especially in the Quote Like Operators section (in the <<EOF sub-section) of perlop.

Replies are listed 'Best First'.
Re^2: Using <<EOL > output.out and EOL
by newbie01.perl (Sexton) on Nov 30, 2009 at 06:15 UTC

    Hi Anomalous Monk,

    If you don't mind doing a quick lookup please ...

    I tried out the following suggestion from zwon and managed to get something going albeit some errors and cannot worked out where am getting things wrong. Any chance that you may be able to tell what am doing wrong?

    The original sugggested code is as below:

    open my $bash, "|-", "bash >/tmp/out.txt" or die $!; print $bash <<EOL; ls df -h uname -a EOL

    I took out the |- and "bash ..." because I want to be able to do this for both Unix and Windows. I assume you cannot do |- on Windows, is that a correct assumption? If anyone can please tell me why am getting the error for the sqlplus under DOS:, it will be very much appreciated. Thanks in advance.

    Codes below, all is working except for sqlplus under DOS.

    DOS: OS Command - works OK: open(OUTPUT, " > eol_dos.out") or die $!; print OUTPUT <<`EOL`; dir EOL exit 0; sqlplus - this gives error : << was unexpected at this time. $ENV{'ORACLE_SID'}="TEST"; $ENV{'ORACLE_HOME'}="C:\oracle\product\10.2.0"; open(OUTPUT, " > eol_sqlplus_dos.out") or die $!; print OUTPUT <<`EOL`; sqlplus -S "/as sysdba" <<"SQLEND" set heading off alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS' ; select 'Connected to the database on ' || sysdate from dual ; SQLEND EOL exit 0 UNIX: OS Command - works OK: open(OUTPUT, " > eol_unix.out") or die $!; print OUTPUT <<`EOL`; ls echo echo "+----------------------------------------------+" echo df echo echo "+----------------------------------------------+" echo uname -a EOL exit 0; sqlplus - works OK: $ENV{'ORACLE_SID'}="test"; $ENV{'ORACLE_HOME'}="/oracle/product/10.2.0"; open(OUTPUT, " > eol_sqlplus_unix_02.out") or die $!; print OUTPUT <<`EOL`; echo "Today is `date`" echo echo "+----------------------------------------------+" echo sqlplus -S "/as sysdba" <<"SQLEND" set heading off alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS' ; select 'Connected to the database on ' || sysdate from dual ; SQLEND echo echo "+----------------------------------------------+" echo EOL exit 0
      I assume you cannot do |- on Windows, is that a correct assumption?
      No. Consider the code:
      # p_1.pl use warnings; use strict; open my $ph, '|-', 'perl p_2.pl' or die 'opening pipe to p_2: $!'; print $ph <<EOP; hi there bye now EOP close $ph or die 'closing: $!'; print "$0 exiting \n"; exit; # p_2.pl use warnings; use strict; print "in $0: \U$_" while <STDIN>; print "in $0: exiting \n"; exit;
      And output:
      >perl p_1.pl in p_2.pl: HI THERE in p_2.pl: BYE NOW in p_2.pl: exiting p_1.pl exiting
      For the rest, please see ikegami's Re^3: Using <<EOL > output.out and EOL.

        Thanks a lot. I sure do have a long, long, long, long way to go on these Perl stuff

        But just to clear up my head, |- means pipe the result of perl p_2.pl to open my $ph?