can we source a shell script in the perl script??
Example: Program 1:
cat test1.sh
#!/bin/ksh
DATE=/bin/date
program 2:
<
You can't source shell files in Perl 5. Sourcing is literally running the commands in the shell file in the target shell; however, it is trivial to open and read the file:
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
sub source {
my $file = shift;
open my $fh, "<", $file
or croak "could not open $file: $!";
while (<$fh>) {
chomp;
#FIXME: this regex isn't quite good enough
next unless my ($var, $value) = /\s*(\w+)=([^#]+)/;
$ENV{$var} = $value;
}
}
source "./test1.sh";
print "$ENV{DATE}\n";