Terminal ANSI colors does not work with Inline::Perl5 (Data::Printer) - raku

The following Perl 5 script:
use strict;
use warnings;
use Data::Printer;
my #a = (1,2,3,4);
p #a;
gives output:
(note the blue color), whereas this Perl 6 scripts:
use Data::Printer:from<Perl5>;
my #a = 1,2,3,4;
p #a;
gives output:
[
[0] 1,
[1] 2,
[2] 3,
[3] 4
]
but the numbers are not colored (as for the Perl 5 case above).
System information:
$ perl --version
This is perl 5, version 29, subversion 3 (v5.29.3) built for x86_64-linux
$ perl6 -e '.say for $*DISTRO, $*VM, $*PERL.compiler.version'
ubuntu (18.10.Cosmic.Cuttlefish)
moar (2018.11)
v2018.11

This seems to be an issue with version 0.40 of Data::Printer which is the current version on metacpan. If I install version 0.99 from GitHub I get colors with Perl 6 also. See also this issue.
I debugged version 0.40 a little bit, and it seems like the only difference between the call to p #a from Perl 5 version versus the same call from Perl 6, is that the Perl 6 call is called in list context, so wantarray returns true for the Perl 6 call, this apparantly makes Data::Printer turn off coloring somehow.

Related

perldoc: 'ŷ' output as 'X' with "=encoding utf8"

When writing POD documentation, I realized that Unicode character ŷ became X on output.
Input:
=pod
=encoding utf8
=over
=item I<yt> (ŷ(t))
The value predicted for time I<t>.
=back
Output in PuTTY:
Input in Emacs:
Version of perldoc being used that of Perl 5.18.2 (SLES12 SP4, perl-5.18.2-12.20.1.x86_64), and LANG=en_US.UTF-8.
Update:
It seems to be a bug in Perl or in the package of SLES12 SP4: Using the same test on OpenSUSE Leap 15.1 with Perl 5.26.1, the output looks OK:
yt (ŷ(t))
The value predicted for time t.
However using pod2man from perl-5.26.1-15.87.x86_64 of openSUSE Leap 15.3, the output is not correct.
OTOH using perldoc the output is correct, too.

Cannot import Perl5 module using Inline::Perl5 into Perl6

I'm trying to import a Perl5 module I really like https://metacpan.org/pod/Data::Printer
using advice from the manual page https://modules.perl6.org/dist/Inline::Perl5:cpan:NINE
using a very simple script
use Inline::Perl5;
my $p5 = Inline::Perl5.new;
$p5.use('Data::Printer');
but then I get this error:
Unsupported type NativeCall::Types::Pointer<94774650480224> in p5_to_p6
in method p5_to_p6_type at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 298
in method unpack_return_values at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 375
in method invoke at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 446
in method import at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 776
in method use at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 898
in block <unit> at inline_perl5.p6 line 4
what is going wrong here? How can I import this perl5 module into perl6? I would also be happy if there is a similar way to get the colored/tabbed output in Perl6 like I would get from Data::Printer because I can't find it.
EDIT: This is solved here: how to load Perl5's Data::Printer in Perl6?
I think you stumbled on a bug in Inline::Perl5 that seems to happen for the Data::Printer Perl 5 module, so I would suggest you open an issue for it at https://github.com/niner/Inline-Perl5/issues .
Meanwhile, the syntax has become much simpler. Once you have Inline::Perl5 installed, you only need to add the :from<Perl5> adverb to load a module from Perl 5:
use Data::Printer:from<Perl5>;
Unfortunately, at this moment that creates the same error that you already described:
===SORRY!===
Unsupported type NativeCall::Types::Pointer<140393737675456> in p5_to_p6
So I don't think there is a solution this that wouldn't require an upgrade of either Inline::Perl5 or Rakudo Perl 6.
From the github page, https://github.com/niner/Inline-Perl5/issues/128
> perl6 -Ilib -e 'use Data::Printer:from<Perl5>; my #a = 1, 2, [3, 4, ${a => 1}]; p #a'
[
[0] 1,
[1] 2,
[2] [
[0] 3,
[1] 4,
[2] {
a 1
} (tied to Perl6::Hash)
]
]
I'm not particularly happy with this though. This is much more complicated than perl5 would have been. One of the main points of using Perl6 over Perl5 is simpler use and syntax. This isn't it. The 'Inline::Perl5' module should be able to be loaded within the script like every other module, not as an option at the command line.

Perl6 sub MAIN/ command line Parsing

In Perl 5, I was able to set an option multiple times like in this question:
Perl Getopt Using Same Option Multiple Times
I am wondering if it's possible to do the same with Perl 6 and the MAIN sub ?
If you define your named parameters as an array then it just works :
perl6 -e 'sub MAIN( :#test ) { say #test }' --test=1 --test=2 --test=3
[1 2 3]

Jython stalls on 1 = 2

I have been investigating jython a bit, and at the jython terminal accidentally typed 1 = 2 instead of q = 2, and found this:
>>> 1 = 2
...
...
I had to Ctrl+C to get out of it. No other input seems to make it happy.
I put the same code in a script and ran it with the same behavior (it just hangs).
In CPython, I get a SyntaxError: can't assign to literal (as expected).
Any idea what's going on? Is this just a jython bug?
$ jython
Jython 2.5.2 (Debian:hg/91332231a448, Jun 3 2012, 09:02:34)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_51

Write a batch to check and return values from SQL and then run scripts determined by the return

Is it possible to write a batch file that will check and return a value from SQL and run a particular set of scripts depending of the return value from SQL.
For example,
If this returns a version 5 value:
sqlcmd -U *** -P *** -S127.0.0.1 -Q "checkversion.sql"
Run version 5 scripts, but ignore 1, 2, 3 and 4.
But if this returns a version 6 value:
sqlcmd -U *** -P *** -S127.0.0.1 -Q "checkversion.sql"
Run version 5 and version 6 scripts but ignore 1, 2, 3 and 4.
Do it all in TSQL because you can nest stored procedures