Mad_Mac has asked for the wisdom of the Perl Monks concerning the following question:

I have a bit of code I've used more than once when programming in Windows. I often suspect there is a more elegant single line that will accomplish the same thing

my $appPath=`echo %localappdata%`; chomp $appPath; my $applicationPath="$appPath".'\someApplication\';

Is there a way to compress this into fewer steps?

Thanks

EDIT

After the advice of the wise and patient monks, I was able to replace those 3 lines of code with one:

my $appPath = "$ENV{localappdata}\\someApplication";

NICE.

Replies are listed 'Best First'.
Re: Chomp, Concatenation and paths
by Anonymous Monk on Jun 25, 2010 at 17:13 UTC

    Did you mean $ENV{localappdata}?

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

        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.

        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.