Reputation: 3307
I've defined a path (say, $MYPAT) in .bashrc file and I would like to use it in perl scripts, so that inside the script I just can write open(IN, "<$MYPAT/dir1/..
. How can I import this variable to directly use it in my script?
I guess is the same problem posted here How to use aliases defined in .bashrc in shell script but applied to perl.
Thank you!
Upvotes: 0
Views: 749
Reputation: 177
There are so many modules for every work to make it possible. I think this module in CPAN would be helpful for you, just go through a little documentation.
Shell::Source
Upvotes: 1
Reputation: 67028
Assuming $MYPAT
is an environment variable defined in your .bashrc, you can access it using the special %ENV
hash in perl, which contains all the environment variables for your process. See %ENV
in perlvar.
my $path = $ENV{MYPAT};
Also, as a stylistic note:
So instead of
open(IN, "<$path/dir1/...")
make that
open my $fh, '<', "$path/dir1/..." or die "yadda yadda";
Upvotes: 3