in reply to assigning a perl variable in shell

You might want to reconsider your design, since embedding Perl scripts in shell scripts has a couple of tricky aspects and can make maintenance a bit less fun. The easiest might be to put your Perl script into a separate file and just run that, or even inverting the design, that is, write most of your script in Perl, and then call external commands via system or a module like IPC::System::Simple.

Having said that, two relatively easy ways to pass shell script variables into Perl: Pass the variables as arguments on the command line of perl and then in your script access them via @ARGV, or, if the variables are visible in the environment, use the %ENV hash to access them.

I'm noticing if I try to assign a variable in perl like $dog, the shell script gives me an error.

What's the error message? There is no $dog in your sample code.

Replies are listed 'Best First'.
Re^2: assigning a perl variable in shell
by scheidr (Novice) on Jan 13, 2015 at 20:22 UTC

    Thanks for the response!

    Use $Tombstone in place of $dog as the example of a perl variable in the script that throws an error.

    It looks like I'd use %ENV on the UNIX shell variable $fruit. Is that true or am I to use the %ENV on the perl variable $tombstone?

    Also I like the idea of going all Perl or calling an entire Perl script. The trouble is we are an all UNIX shell shop and If I started throwing Perl scripts around it would blow peoples minds. I don't want to stir that up. I just want to be able to access perl from time to time to use it's vast array of functions instead of using awk or exp or something else. For example UNIX doesn't have an index function that returns the positional value of a string when fed. But Perl does! So just simple "one offs" like that are what I'd want to use this for.

      Also I like the idea of going all Perl or calling an entire Perl script. The trouble is we are an all UNIX shell shop and If I started throwing Perl scripts around it would blow peoples minds.
      If you'd like to blow people's minds with specific reasons to write the whole thing in Perl see:

        Nice but I honestly don't think I could get that many people here motivated to all learn Perl at once.

        Thanks anyway!

A reply falls below the community's threshold of quality. You may see it by logging in.