Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jhuni (9050)

  (email not shown publicly)
Yahoo! ID: (Add User, Send Message)

Journal of jhuni (9050)

Friday March 19, 2010
06:21 AM

More Rosetta code written in Perl6

I added a solution to the dot product, which it turns out was very easy knowing Perl6 meta operators:

[+] ( @a <<*>> @b )

Another problem I worked on is this missing permutations problem, which I solved using cross operators, yet it still doesn't feel that elegant to repeat things four times:

[X~] @letters = @letters X~ @letters X~ @letters X~ @letters

I would've used the [X~] operator, however, it does not seem to work in any implementation yet, so instead I wrote things like on the right hand side, which is quite messy. The only other thing which is sort of interesting is the code to check duplicates. I forget about the uniq function for a while so I wrote this messy code to check for duplicates:

sub lacksDuplicates($str) {

    my @chars = $str.split('');
    my @pastValues;

    for @chars -> $char {

        return ?(0) if $char eq any @pastValues;


    return ?(1);


Fortunately we have uniq so I wrote something more pleasant instead:

.chars == .split('').uniq.elems
Thursday March 18, 2010
02:00 AM

Perl6 code

I uploaded a repository containing lots of perl6 examples/code that I have written over the years:

Most of that code is stuff that I put on wikis such as I will probably add more to that repository over the days to come, however, I intend to focus on more practical applications now then just learning and examples. But in the mean time I found this page on Rosetta code and I would like to briefly rant about it:

That page asks you to solve the problem of printing the following triangle of asterisks:


I just feel that the solutions written in Perl6 on that page are more elegant then those written in any of the other languages. Part of this is the quantity of characters. Perl6 has the least, perhaps due to the great new operators and the fact that you can exclude parenthesis.

import sys
for i in xrange(5):
    for j in xrange(i+1):

This solution from that link makes me wonder... who ever said Python is readable? How many people actually know what stdout is, and how many people are going to know what a blank print statement does? Admittely, that code is constrained because Rosetta code asked that two nested loops be used, so lets look at a more "Pythonic" way of doing things:

for i in range(1,6):
    print '*' * i

I don't think that code is actually that much better because the * character is used to replicate strings and it just so happens to be the character which is being replicated! Furthermore, it is confusing that the range is represented as range(1,6) when the actual triangle you need to print is 1..5.

say '*' x $_ for 1..5;

How about that? It is only 22 characters, as opposed to 96 and 38 for the Python solutions. Even constrained by the condition that you have to use two for loops, the perl6 solution is still elegant because you can leave off parenthesis.

([\~] "*" xx 5).join("\n").say;

This is another solution using triangular reduction operators, which are a new feature in Perl6. It doesn't seem to be as elegant as the previous example, but I still think it is nice. Related to that, you can calculate the number of asteriks in that triangle using reduction operators: ([+] 1..5 == 15). Anyways I think that is enough of a rant for today =/
Wednesday September 09, 2009
03:59 AM


I have been developing on JSAN recently since it was fixed. It is a little lonely though because it is nothing near as popular as CPAN. I noticed though that the JSAN loader is super slow so I have been using "Tasks" a lot, which are basically JavaScript files containing many modules in one, this has saved me from HTTP requests and bandwidth on my website.

The sad thing thing is I still use PHP on my website which is disgusting. In my opinion get_file_contents makes a lot more sense then file_get_contents, it just doesn't sound right in English to say file_get_contents so I tend to get in wrong all the time. I simply fail at coding whenever I try to use PHP, which is okay though because I have been moving everything I can to the client-side with JavaScript.