http://www.perlmonks.org?node_id=1011177


in reply to accessing an environment variable dynamically

Welcome to Perl (I read your profile page, glad you are jumping in).

Now then, could you please let us know -- what is the real objective you are wanting to meet here? What is the core problem you are trying to solve? Are you trying to compare 2 directories? Is that it?

Let's break down the problem to its simplest form and work up from there...

--
Tommy
  • Comment on Re: accessing an environment variable dynamically

Replies are listed 'Best First'.
Re^2: accessing an environment variable dynamically
by JennieInMI (Acolyte) on Jan 01, 2013 at 20:58 UTC

    Thanks for the welcome.

    It's pretty much just what I asked in my initial post. I need to compare two folders and find out if the content is identical. I've got a BC3 script that does that. Supposedly, it sets the %errorLevel% environment variable when it's done executing and I should be able to capture that and use that value to inform my Perl script of the success or failure of that comparison, but I'm not having a lot of sucess. Thus the questions I listed.

    If this doesn't work I can parse the report generated by my BC3 script, but this SEEMED the easier option. Also, the current manual audit process specifies a BC3 comparison so I'd like to honor that. If I need to do it differently though, I think that'd be fine as long as it is accurate.

    Also, I think learning how to do this correctly will be really valuable in the long run. Scripts generally tend to do a lot of interacting with the environment they run on so becoming adept at accessing and utilizing those values seems like a smart plan.

    Thanks so much for being so willing to jump in and help another coder.

    Jennie

      Ok, so here's what you want to do: listen to BrowserUK who is brilliant with Perl on Windows. BrowserUK is right that you need to focus on the value of $? after you run your system call. Personally, I like to dig a little deeper and avoid the shell as much as possible when running system commands, so I use IPC::Open3, for example.

      But for your project here, using the system() command or qx{} will probably serve you just fine. Read the perldoc -f system documentation, and you'll see it's quite doable.