in reply to Re: Chomp, Concatenation and paths
in thread Chomp, Concatenation and paths

I don't think so ...? But maybe I don't understand. I'm not familiar with the syntax you suggested ...

Replies are listed 'Best First'.
Re^3: Chomp, Concatenation and paths
by Corion (Patriarch) on Jun 25, 2010 at 17:33 UTC

    The anonymous frère likely meant to tell you that the environment is mapped bidirectionally into Perl as the %ENV hash. See perlvar about all special Perl variables.

      OK, I get it. I could use that instead of a system call. I don't see how that saves me a step, other than maybe I don't need to chomp?

        "One step" is quite an understatement. You're spawning a new process (which involves fetching %ENV), executing a shell, executing a shell command, checking for errors (or not) and parsing the response in order to get a value Perl already had to begin with.

        Using $ENV{localappdata} saves an incredible number of steps.

        Also, it doesn't return "Echo is on" if the variable isn't set, and it's portable.

        Update: Added last paragraph.

        print "$ENV{localappdata}\\someApplication\\";
Re^3: Chomp, Concatenation and paths
by sierpinski (Chaplain) on Jun 25, 2010 at 19:23 UTC
    Print the contents of %ENV, and you'll see exactly what they were talking about. It contains all of your environment variables for whatever shell you're running the script in. Very useful to see what's available to your perl program.

      OK. Sorry for being a little slow. I finally had a few minutes to play around with this. This is definitely a better way to do it. Thanks for the help.