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

Has anyone ran into problems with Windows PowerShell and Perl? I am running ActiveState's 5.10, build 1002, on Win XP SP2, with PS 1.0 installed. When I run the command

perl -e "$_ = 1"

I get the following message:
syntax error at -e line 1, near "=" Execution of -e aborted due to compilation errors.
On MS Dos, this works fine. Any thoughts?

Replies are listed 'Best First'.
Re: Invocation in PowerShell not working
by NetWallah (Canon) on Mar 13, 2008 at 17:55 UTC
    $_ is being interpolated by the powershell (it means The current pipeline object, used in script block).

    Try it with single-quotes. I have see some conflicting references, saying that non-interpolated strings are enclosed in backticks (They call them Apostrophes) or this character ’’, but single-quotes should work.

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

      Thanks! That did it!
Re: Invocation in PowerShell not working
by moritz (Cardinal) on Mar 13, 2008 at 17:21 UTC
    I have no experience with PowerShell, but if it has similar interpolation syntax to unix shells, you have to use doublesingle quotes: perl -e '$_ = 1'

    In unix shells variables are interpolated into double quotes, and since you probably have no variable $_ defined in your shell, the one-liner that perl sees looks l ike this:  = 1;

    Update: s/double/single/, thank you BrowserUk