http://qs321.pair.com?node_id=11137651

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

Hi

we often exchange one-liners here or short snippets like the following.

That's very handy for quick demos without the need of a temp file. ( like from kcott here)

$ perl -E ' use strict; use warnings; use feature "declared_refs"; no warnings "experimental::declared_refs"; say ref my \$scalar; say ref my \@array; ' SCALAR ARRAY

unfortunately this sucks on Win/CMD because it doesn't like simple quotes°

D:\tmp\pm>perl -E'say $]' Can't find string terminator "'" anywhere before EOF at -e line 1.

The best OS agnostic approach - well the only I'm aware of - is typing to STDIN with a final __END__

D:\tmp\pm>perl -M5.012 use strict; use warnings; use feature "declared_refs"; no warnings "experimental::declared_refs"; say ref my \$scalar; say ref my \@array; __END__ SCALAR ARRAY

So far so good ... (well it's not so good for in-place editing but then a temp file might be better anyway)

But did you notice the -M5.012 I had to add? It means use 5.012 and it's there to compensate the -E which activated all current features. But simply using -E will deactivate reading from STDIN and say was added with 5.12 ... (details perlrun )

Question: Is there a shorter way to do this?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

UPDATE

°) the truth is even far worse. One needs to replace the surrounding ' with " and all internal "..." with qq(...) and worry about the right delimiter.