wall-nut
wall-nut

Reputation: 403

running Strawberry Perl in Windows 8 PowerShell ISE

I am trying to run multiple Perl commands from the command line in PowerShell in Windows 8.

This works

perl -e "print 'Joe'";

This prints:

Joe

This does not work

perl -e "my $string = 'Joe'; print $string;"

This gives me an error

perl : syntax error at -e line 1, near "my  ="
At line:1 char:1
+ perl -e "my $string = 'Joe'; print $string;"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (syntax error at -e line 1, near "my  =":String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Execution of -e aborted due to compilation errors.

Can someone point out the obvious mistake I am missing? Thanks. I usually do this on UNIX but use back ticks. as a wrapper instead of double quotes.

Upvotes: 2

Views: 1053

Answers (1)

CB.
CB.

Reputation: 60918

try this, but I can't test it

perl -e 'my $string = ''Joe''; print $string;'

In powershell $string is a variable, and in double quotes variable are expanded with the value assigned. In single quotes are take as literal. To escape ' in single quotes redouble it as ''

or try:

perl -e  "my `$string = 'Joe'; print `$string;"

the ` is the escape character in powershell.

Upvotes: 8

Related Questions