in reply to 99 Problems in Perl6

@flattened.perl.say;

What is this .perl method? Needless to .say, it's not easy to search for.

We're building the house of the future together.

Replies are listed 'Best First'.
Re^2: 99 Problems in Perl6
by Ovid (Cardinal) on Dec 15, 2006 at 22:37 UTC

    It's kind of like a poor man's Data::Dumper. For example, if you want to see all of your environment variables, you can use this:

    %*ENV.perl.say;

    That will represent %*ENV (remember that the '*' twigil means it's global) in a way that's legal Perl6 code. I use it because it makes complex data structures much easier to read. I don't know if it's possible to customize the output, though. Right now it's all one one line.

    You can still do this:

    %*ENV.say;

    You won't find the output as legible, though.

    And while we're on the topic of environment variables, use the '+' twigil to read them. What to see the 'HOME' environment variable?

    $+HOME.say

    Update: the one thing I really want is for reflection to be added to Pugs so I can query an object for its methods. That will be a huge productivity boost so we can see exactly what we can play with.

    Cheers,
    Ovid

    New address of my CGI Course.

Re^2: 99 Problems in Perl6
by gaal (Parson) on Dec 15, 2006 at 22:46 UTC
    What Ovid said. There's also a .yaml method that does the YAML::Syck::Dump equivalent. The round trip is also analogous:

    eval $obj.perl; eval $obj.yaml :lang<yaml>; # though this syntax is unspecced and +may change.
Re^2: 99 Problems in Perl6
by Util (Priest) on Dec 15, 2006 at 23:52 UTC
    From S02:
    To get a Perlish representation of any object, use the .perl method. Like the Data::Dumper module in Perl 5, the .perl method will put quotes around strings, square brackets around list values, curlies around hash values, constructors around objects, etc., so that Perl can evaluate the result back to the same object.