Pages

Learning Perl is Fun

In this holiday, I have an ambitious to learning a programming language. One of my dream is to be a developer for some free open source software (FOSS). But, for that reason, I think at least I must master one programming language. And I choose Perl in this occasion.
 PerlImage via Wikipedia
Perl is an easy language to learn. For a few week, it's easy for me to understand some standard concept in programming. The language itself not so hard to understand. Many simplicity that this language offer to the programmer. Learning this language is same as learning human language instead of computer language. If you have a spare time, better to try learning this language.

Book that I use for learning this language is available for free in the Internet. Its title is Beginning Perl by Simon Cozens. You can download it in this link. But that book are separated by chapter, so for you that want to download a whole book, you can follow this link (created by myself using gs command).

Now, I have landed in chapter 4. And after a long journey to this chapter, a successfully executed program have created by myself. Check this:
#!/usr/bin/perl 
# ara.pl
# version 2.0
use strict;
use warnings;
use 5.010;
use List::Util 'shuffle';

my $jml_siswa = <stdin>;
my $jml_kelompok = <stdin>;
chomp ($jml_siswa, $jml_kelompok);

my @acak_absen = shuffle (1 .. $jml_siswa); #bugs for $jml_siswa = 1

my $sisa = $jml_siswa % $jml_kelompok;
my $hasil = ($jml_siswa - $sisa) / $jml_kelompok;

my @byk_agt_kel = ($hasil) x $jml_kelompok;

if ($sisa) {
 do {
  $sisa--;
  $byk_agt_kel[$sisa]++;
 } while ($sisa);
 @byk_agt_kel = shuffle @byk_agt_kel;
}

my $i = 0; my $j = 1;

while (@acak_absen) {
 print "Anggota kelompok $j adalah:\n"; $j++;
 do {
  $byk_agt_kel[$i]--;
  my $k = pop @acak_absen;
  print "no. absen $k\n";
 } while ($byk_agt_kel[$i]);
 $i++;
} 
Try to understand it. It's fun.
Enhanced by Zemanta