Newbie here, I would like to ask if it is possible to use perl commands inside a shell script? i created a simple script which connects to oracle and run queries which the script saves to a separate .txt file for each query issued. What i want to do is to create a presentable and well formatted excel file containing all the queries saved in the txt files. I saw from a post here in unix.com which points a link where it is possible to format excel via perl.
yeah i'm trying, but it wont work. is there any startup code or whatsoever that i should do before i can start running perl commands? i specifically want to try Excel::Writer::XLSX for my script. Please help me!
You can use Perl inside a shell script, you just can't mangle it together as you please. This is an example of how to do it.
#!/usr/bin/ksh
echo "This is the shell script"
perl << 'EOF'
use strict;
use warnings;
my $var = "This is the Perl script\n";
print $var;
EOF
echo "This is the shell script again"
Actually the technique called "Here Document" or "heredoc" will do the trick. The string EOF could be anything that is not a reserved word. The lines between << 'EOF' and the line containing only EOF are fed to perl as standard input. Any way to feed perls standard input works, like:
#!/usr/bin/ksh
echo "This is the shell script"
echo 'use strict; use warnings; my $var = "This is perl\n"; print $var;' |perl
echo "This is the shell script again"
If you want to reuse the perl-code in another script I'd put the code in a seperate perl-script and call that from within your shellscript.
echo "This is the shell script"
perl -w /path/to/your/perlscript.pl
echo "This is the shell script again"