Script para formar parejas para programación de a pares
#!/usr/bin/perl -s
# File: pairing.pl
# Perl Scrip to Pairing in Pair programming
# Command line example:
# perl pairing.pl "Dario" "Karina" "Claudia" "Pancho"
use strict;
use warnings;
# Begin main
# @ARGV is a array of command line arguments
if (scalar @ARGV > 0){
runPairing(\@ARGV);
}else{
print "No arguments. Enter names. For example: \n";
print "perl pairing.pl \"name1\" \"name2\" \"name3\" \"name4\" \n";
}
# End main
# Run pairing
sub runPairing{
my ($members) = @_; #array reference
my $members_count = scalar @{$members};
my $pair_count = 1;
do{
my $first_selected = getMemberAndRemoveItRandom($members);
$members_count = $members_count - 1;
if ($members_count > 0){
my $second_selected = getMemberAndRemoveItRandom($members);
$members_count = $members_count - 1;
print "Pair $pair_count: " . $first_selected;
print " - " . $second_selected . " \n";
}else{
print "Pair $pair_count: " . $first_selected . " - none\n";
}
$pair_count = $pair_count + 1;
} until($members_count==0);
}
# Retrieves a member and removes it from the array.
sub getMemberAndRemoveItRandom{
my ($members) = @_; #array reference
my $size = scalar @{$members};
my $random_number = int(rand($size));
my $removed_member = splice @{$members}, $random_number, 1;
return $removed_member;
}
No hay comentarios:
Publicar un comentario