perlquestion
LanX
Hi<P>
we often exchange one-liners here or short snippets like the following.<P>
That's very handy for quick demos without the need of a temp file. ( like from [kcott] [id://11137648|here])<P>
<c>
$ 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
</c><P>
unfortunately this sucks on Win/CMD because it doesn't like simple quotes°<P>
<c>
D:\tmp\pm>perl -E'say $]'
Can't find string terminator "'" anywhere before EOF at -e line 1.
</c><P>
The best OS agnostic approach - well the only I'm aware of - is typing to STDIN with a final <C>__END__</C><P>
<c>
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
</c><P>
So far so good ... (well it's not so good for in-place editing but then a temp file might be better anyway)<P>
But did you notice the <C>-M5.012</C> I had to add? It means <C>use 5.012</C> and it's there to compensate the <C>-E</C> which activated all current features. But simply using -E will deactivate reading from STDIN and [DOC://say|<tt>say</tt>] was added with 5.12 ... (details [DOC://perlrun|<tt>perlrun</tt>] )<P>
<B>Question:</B> Is there a shorter way to do this? <P>
<div class="pmsig"><div class="pmsig-708738">
<!--nowiki--><p>Cheers Rolf<br>
<sub>(addicted to the Perl Programming Language :)
<br> <i> [id://1153804|Wikisyntax for the Monastery]</i>
</sub>
<!--nowiki-->
</div></div><P>
<H5> UPDATE</H5><P>
°) the truth is even far worse. One needs to replace the surrounding <C>'</C> with <C>"</C> and all internal <C>"..."</C> with <C>qq(...)</C> and worry about the right delimiter.<!-- Wiki2Monks {"version":1.161} -->