Skip to content

Instantly share code, notes, and snippets.

@sputnick-dev
Created June 20, 2012 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sputnick-dev/2961747 to your computer and use it in GitHub Desktop.
Save sputnick-dev/2961747 to your computer and use it in GitHub Desktop.
use threads;
#!/usr/bin/env perl
use strict; use warnings;
use threads;
use threads::shared;
use YAML::AppConfig;
use Data::Dumper;
$|++;
my $conf_file = "compteur_cours.yaml";
my $conf = YAML::AppConfig->new(file => $conf_file)
or die "A-peut-pas charger la conf :/\n";
print "Demarrage:\n>>> ";
my $dec = ord(getc);
my $key = chr($dec);
if ($key eq 'd') {
print "On demarre le cours\n";
} else {
die "What's wrong with you dude ?\n";
}
my @threads;
foreach my $fn (keys %{$conf->{config}->{prix}}) {
push @threads, threads->new(\&CoursNow, $fn, $conf->{config}->{prix}->{$fn});
}
$_->join for @threads;
sub CoursNow {
my ($fn, $price) = @_;
print "\r>>> ";
until ($key eq 'f') {
my $dec = ord(getc);
my $key = chr($dec);
$price += $price / 3600 * 2;
if ($key eq 'f') {
printf("%s doit %.2f\n", $fn, $price);
threads->exit;
}
sleep(0.5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment