Simple one-liners may be specified as command line arguments to perl using the -e
switch (think "execute"):
perl -e'print "Hello, World!\n"'
Due to Windows quoting rules you can't use single-quoted strings but have to use one of these variants:
perl -e"print qq(Hello, World!\n)"
perl -e"print \"Hello, World!\n\""
Note that to avoid breaking old code, only syntax available up to Perl 5.8.x can be used with -e
. To use anything newer your perl version may support, use -E
instead. E.g. to use say
available from 5.10.0 on plus Unicode 6.0 from >=v5.14.0 (also uses -CO
to make sure STDOUT
prints UTF-8):
perl -CO -E'say "\N{PILE OF POO}"'