I have variables in a bash script that I need to be carried over into a perl one. I have the variables $gal and $obsid declared in the bash script, and then I call the new program.
gal=UCLA121
obsid=1896
./my_program
The beginning of the perl script loads an image with the phrase
$ph_im = "./$gal/img/${obsid}.img";
But the variables are NULL in the new program.
Making variables available to child process in shell script can be done either by exporting variables
Or by calling program with variables prepended
In either case you will need to call
ENV
on them inside perl scriptUsing the environment is a cleaner way.
There is the
-s
switch:If you are calling it like
You can use
@ARGV
. E.g.Example source.
This is an old example, so it may not be using the latest style. I don't have a perl compiler set up at the moment, so I can't test the output.
You can use the
Data::Dumper
to help you debug things.If you are calling it like
Realize that you may get weird results mixing
@ARGV
and named parameters. You might want to change how you call it to something likeor
Note also that the named parameters are
-gal
, not-$gal
. I'm not quite sure what the$
would do there, but it would tend to do something other than what happens without it.Remember,
Data::Dumper
can help you debug things if you get confusing results.