Forgot your password?
typodupeerror
Perl

Journal: Merge Sort

Journal by glimmy

A little snippet of Perl, and the first Perl I have done in a long while. Still waiting for Perl 6...

sub merge {
    my ($left, $right) = @_;
    my @merged;
 
    while ((scalar(@$left) > 0) && (scalar(@$right))) {
 
        if ($left->[0] <= $right->[0]) {
            push @merged, shift(@$left);
        } else {
            push @merged, shift(@$right);
        }
    }
 
    if (scalar(@$left) > 0) {
        push @merged, shift(@$left);
    }
 
    if (scalar(@$right) > 0) {
        push @merged, shift(@$right);
    }
 
    return @merged;
}
 
sub mergesort {
    my @list = @_;
    my (@left,@right);
 
    if (scalar(@list) <= 1) {
        return @list;
    } else {
 
        my $middlin = scalar(@list) / 2;
 
        foreach (0..($middlin - 1)) {
            push @left, $list[$_];
        }
 
        foreach ($middlin..(scalar(@list) - 1)) {
            push @right, $list[$_];
        }
 
        @left = mergesort(@left);
        @right = mergesort(@right);
 
        return &merge(\@left,\@right);
    }
}

Education

Journal: Rules for Writers

Journal by glimmy

Avoid run-on sentences they are hard to read. Don't use no double negatives. Use the semicolon properly, always use it where it is appropriate; and never where it isn't. Reserve the apostrophe for it's proper use and omit it when its not needed. No sentence fragments. Avoid commas, that are unnecessary. Eschew dialect, irregardless. And don't start a sentence with a conjunction. Hyphenate between sy-llables and avoid un-necessary hyphens. Write all adverbial forms correct. Don't use contractions in formal writing. Writing carefully, dangling participles must be avoided. It is incumbent on us to avoid archaisms. Steer clear of incorrect forms of verbs that have snuck in the language. Never, ever use repetitive redundancies. If I've told you once, I've told you a thousand times, resist hyperbole. Also, avoid awkward or affected alliteration. Don't string too many prepositional phrases together unless you are walking through the valley of the shadow of death. "Avoid overuse of 'quotation "marks."'"

"A mind is a terrible thing to have leaking out your ears." -- The League of Sadistic Telepaths

Working...