Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Need Perl6: Inline::Perl5 help

by Todd Chester (Scribe)
on Mar 04, 2017 at 09:39 UTC ( [id://1183634]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

I have a combines Perl 5 and Perl 6 question for you:

I am trying to teach myself the various ways to use Perl 6's Inline::Perl5 module.  So far so good, with one exception:

Xfce 4.12's Terminal
perl 5: v5.24.1
perl 6: Rakudo 2017.01

#!/usr/bin/perl6 use Inline::Perl5; use Term::ANSIColor:from<Perl5>; my $Red = Term::ANSIColor.RED; my $Reset = Term::ANSIColor.RESET; print ( $Red ~ "--Red--" ~ $Reset ~ "\n\n" );
Term::ANSIColor--Red--Term::ANSIColor

In case the html code for red did not come out, it prints out red up to and including the second --

It accepts both the color commands and prints out "Term::ANSIColor" for both the red and the reset command.  How do I get this to stop printing out "Term::ANSIColor"?

Many thanks,
-T

Replies are listed 'Best First'.
Re: Need Perl6: Inline::Perl5 help
by Laurent_R (Canon) on Mar 04, 2017 at 15:49 UTC
    Hi Todd Chester,

    the syntax you use does not work either with Term::ANSIColor used with Perl 5. So, it appears that it is your syntax for using such module that is faulty. Please check the documentation.

    I can't test right now, but perhaps try something along these lines:

    my $red = color("red"); print $red; my $reset = color('reset'); print ( $red ~ "--Red--" ~ $reset ~ "foo\n\n" );
    or possibly:
    my $red = Term::ANSIColor::color("red"); print $red; my $reset = Term::ANSIColor::color('reset'); print ( $red ~ "--Red--" ~ $reset ~ "foo\n\n" );
    Update: Fixed a capital letter at the beginning of a variable.
Re: Need Perl6: Inline::Perl5 help
by duelafn (Parson) on Mar 05, 2017 at 15:36 UTC

    This works:

    #!/usr/bin/perl6 use Inline::Perl5; use Term::ANSIColor:from<Perl5> <color RED RESET>; my $Red = color("red"); my $Reset = color("reset"); say $Red ~ "--Red--" ~ $Reset; say RED ~ "--Red--" ~ RESET; say "{RED}--Red--{RESET}"; # And Laurent_R is right: my $Blue = Term::ANSIColor::color("blue"); say $Blue ~ "--Blue--" ~ $Reset;

    Update: Another approach which works:

    my $p5 = Inline::Perl5.new; $p5.use('Term::ANSIColor'); my $Green = $p5.call('Term::ANSIColor::GREEN'); say $Green ~ "--Green--" ~ $Reset;

    However, this doesn't work (was trying to get around the AUTOLOAD):

    Term::ANSIColor.YELLOW; # AUTOLOAD should generate YELLOW my $Yellow = Term::ANSIColor::YELLOW; # Hmm, nope :( at least not v +isible to Perl6 say $Yellow ~ "--Yellow--" ~ $Reset;

    Good Day,
        Dean

      Thank you all for the help and tips!

      Followup,

      This is my notes on Inline::Perl5. I hope this is useful to others.

      -T


      #!/usr/bin/perl6 # Inline::Perl5 test # Reference: https://github.com/niner/Inline-Perl5/commit/cc683dae98df +19db8cfbb551f7a87ef79bdc2a8b use Inline::Perl5; use Term::ANSIColor:from<Perl5>; # my $Red = Term::ANSIColor.RED; # my $Reset = Term::ANSIColor.RESET; my $Red = color('red'); my $Reset = color('reset'); print "High Level method:\n"; print $Red ~ "--Red--" ~ $Reset ~ "\n\n"; print "Low Level method:\n"; my $P5Color = Inline::Perl5.new; $P5Color.use( 'Term::ANSIColor' ); my $ResetColor = "RESET"; print ( $P5Color.call( 'Term::ANSIColor::GREEN' ) ~ "Red\n" ~ $P5Color.call( "Term::ANSIColor::$ResetColor" ) ~ "\n" ); my $p6str = "Perl 6 String"; my $perl5colors = Inline::Perl5.new(); $perl5colors.run(qq{ use Term::ANSIColor qw [ BLUE RESET ]; print "p5 term with color\n" . BLUE . "I am blue\n" . "$p6str" . RESET . "\n\n"; }); print "\'run\' method:\n"; my $perl5 = Inline::Perl5.new(); $perl5.run( ' print "Perl 5\' local time is " . localtime . "\n\n"; ' +); print "Test of return values\n"; my $RetStr = Inline::Perl5.new(); print $RetStr.run(qq{ return ( "P5 return string\n\n" ) });
Re: Need Perl6: Inline::Perl5 help
by Anonymous Monk on Mar 04, 2017 at 18:27 UTC
    Term::ANSIColor uses AUTOLOAD for those functions, maybe that has something to do with it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1183634]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found