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.


In reply to OS agnostic C&P CLI snippets with -E by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.