Created
June 20, 2012 19:37
-
-
Save sputnick-dev/2961747 to your computer and use it in GitHub Desktop.
use threads;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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