1

I'm trying to set variable for the perl via the -s and -var=value.

perl -s -E 'say $xx if $xx' -xx=abc

prints

No Perl script found in input

It probably didn't works together with the -E or i'm doing something wrong. (the perlrun doesn't mentions about the wrong combination of -E and -s)

1 Answer 1

5

You need a -- to end the built-in perl options and start your user supplied ones:

perl -s -E 'say $xx if $xx' -- -xx=abc

As is, perl thinks you are using its -x switch.

(That said, -s is a really lousy thing to try to use these days; use Getopt::Long.)

Sign up to request clarification or add additional context in comments.

12 Comments

thanx - and yes, the perlrun mentions the -- but didnt understand how it means it. ;)
it doesn't do anything besides separate between perl switches and program name/arguments.
i like the -s idea for the one-liners.
I get this error that goes away when I use double quotes (I replaced say with print since I don't have a say function...): Can't find string terminator "'" anywhere before EOF at -e line 1.
@kobame: how about instead: XX=ABC perl -E 'say $ENV{XX} if $ENV{XX}'
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.