Code Sorter

By Ziddykins on Sep 11, 2014

Tired of having a bunch of messy, disorganized code? Need a little more order in your life?
This is for you.
What this does is sorts your code for you alphabetically and case-insensitively.
Feed it your source and it'll output sorted.code
The code:

#!/usr/bin/perl
#sortcode.pl
use warnings; use strict;

my @line = <>;
my @sort = sort { uc $a cmp uc $b } @line;
open my $fh, '>', 'sorted.code' or die "Cant open file for writing";
print $fh @sort;
close $fh;

For example.

cat me.pl
#!/usr/bin/perl
#me.pl
use warnings; use strict;

while (my $line = <>) {
    chomp ($line);
    if (!$line) { next; }
    my @nums = split(/,/, $line);
    my %numbers;
    foreach my $line (@nums) {
        $numbers{$line}++;
    }
    my $length  = $#nums / 2;
    my $max = (sort {$numbers{$b} <=> $numbers{$a}} keys %numbers)[0];
    if ($numbers{$max} >= $length and $max > 0) {
        print "$max\n"
    } else {
        print "None\n";
    }
}
perl sortcode.pl me.pl
cat sorted.code
        $numbers{$line}++;
        print "$max\n"
        print "None\n";
    chomp ($line);
    foreach my $line (@nums) {
    if (!$line) { next; }
    if ($numbers{$max} >= $length and $max > 0) {
    my $length  = $#nums / 2;
    my $max = (sort {$numbers{$b} <=> $numbers{$a}} keys %numbers)[0];
    my %numbers;
    my @nums = split(/,/, $line);
    }
    }
    } else {
#!/usr/bin/perl
#go.pl
use warnings; use strict;
while (my $line = <>) {
}

Ahh, order.

Comments

Sign in to comment.
Hawkee   -  Sep 12, 2014

I'm a little unclear what this does. Can you elaborate more and explain each block of code?

Ziddykins  -  Sep 12, 2014

It's just a joke. You feed it a file and it sorts it alphabetically; something you wouldn't want with your code.
sortcode.pl is the file, me.pl is the file being fed to it. me.pl is just a program which finds the major element in a list of data. me.pl isn't important, it's just being used as an example.

ProIcons  -  Sep 12, 2014

It ruins the Structure and consistency of the program

Hawkee  -  Sep 12, 2014

I thought that's what I understood, but I just had to ask. Might want to make it more clear that this is a joke.

Ziddykins  -  Sep 13, 2014

The original source is never touched, only read.
The sorted is stored in sorted.code, a new file.
Pretty obvious this is a joke if someone takes the time to read the main description.

Sorasyn  -  Oct 07, 2014

Why bother posting this garbage then?

Ziddykins  -  Oct 13, 2014

So because you can't see the humor in something and have to be super-hard 24/7, everyone else has to as well?
Last I checked this was a place to post code. Pretty sure that's code. While its purpose may not be anything desirable it still shows sorting methods, storing, and proper file handling. The provided example source also has a great deal of interesting /and/ efficient methods. You calling it "garbage" goes to show how you take things at face-value and that's unfortunate and hilarious.

In short: Blow me, Sorasyn. Stick to progress bars.

Sorasyn  -  Oct 15, 2014

I'm sorry, but "face value" would presume the premise that I have no idea what the code actually does. Which is not the case. The code is only as good as the developer, so this "snippet," if it can so be called, speaks volumes about your ability. Your ability which, judging by this snippet, can be accurately summed up by aforementioned comment; "garbage."

Ziddykins  -  Oct 16, 2014

No. No it wouldn't at all, but I suppose face-value was left open to interpretation.
If you're going to sum up the skill of a developer based on nine lines of code as a joke I have some bad news for you.
Your opinion of the code is just that, an opinion.
In my opinion, it's non-malicious fun.
In my opinion, you're a pretentious cunt who can't differentiate opinion and fact.
All wonderful opinions.
Allow me to make it output in rainbow text and echo to an IRC channel; maybe that'll be a little more "Hawkee-ish" for you.

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.