- or download this
print "What Goal In Cash Do You Want To Set? :";
chomp ($goal=<STDIN>);
- or download this
sub query_user {
print @_ if @_;
chomp (my $answer = <STDIN> );
return $answer;
}
- or download this
sub notify_user {
return print @_;
}
- or download this
sub query_user {
notify_user(@_) if @_;
chomp (my $answer = <STDIN> );
return $answer;
}
- or download this
my (%ticker, %portfolio);
my @stock_names = ('Derpco', 'Tetrabytz', 'Mojo Inc', 'Freke', 'Mega')
+;
@portfolio{@stock_names} = (0) x @stock_names;
@ticker{@stock_names} =
map { price => generate_random(10, 100),
volitility => int(rand(7)) * 5 + 5 }, @stock_names;
- or download this
@stocks = (0,0,0,0,0);
$derpco=genRand(10,100);
$tetrabytz=genRand(10,100);
...
$freke=genRand(10,100);
$mega=genRand(10,100);
$cash=genRand(500,1000);
- or download this
#!/usr/bin/perl -w
use strict;
...
$freke=genRand(10,100);
$mega=genRand(10,100);
$cash=genRand(500,1000);
- or download this
#!/usr/bin/perl
use strict;
use diagnostics;
...
return print @_;
}
- or download this
unless ( defined $end ) {
$end = $start;
$start = 0 - $end;
}
- or download this
sub generate_random {
my ($start, $end) = @_;
$end = 0 - ($start = 0 - $start) unless defined $end;
return int( $start + rand($end - $start + 1) );
}
- or download this
$manip=genRand(0,50);
$derpco=$derpco+genRand(-10,10);
$tetrabytz=$tetrabytz+genRand(-40,40);
...
if ($mojoinc < 1){$mojoinc = 0; $stocks[2]=0;};
if ($freke < 1){$freke = 0; $stocks[3]=0;};
if ($mega < 1){$mega = 0; $stocks[4]=0;};
- or download this
# update prices
foreach my $stock ( @ticker{@stock_names} ) {
$$stock{price} += generate_random($$stock{volitility});
...
foreach my $stock ( @stock_names ) {
$portfolio{$stock} = 0 if $ticker{$stock}{price} == 0
}
- or download this
notify_user (
qq|\n\nYour Stock Report for January $date\n\n|,
...
portfolio_value( \%portfolio, \%ticker, ),
qq| in stocks.\n|,
qq|Would you like to (B)uy or (S)ell or are you (D)one? | );
- or download this
sub portfolio_value {
my ($portfolio, $ticker) = @_;
...
for keys %$portfolio;
return $total_value;
}
- or download this
until ( $cash > $goal or $date == 31 ) {
# update prices
...
}
}
}
- or download this
sub sell {
my ($portfolio, $ticker) = @_;
...
}
return $cash;
}
- or download this
buy<CODE> sub routine fixes a bug in the original game which allowed t
+he player to purchase a few million shares when the price reached zer
+o.</P>
<CODE>
sub buy {
...
}
return $cash;
}
- or download this
if ( $cash > $goal ) {
my $dif = $cash - $goal;
...
my $dif = $goal - $cash;
notify_user( qq|Boo! you lost, you missed your goal by \$$dif\n| )
+;
}
- or download this
#!/usr/bin/perl
#require v5.6.1;
...
return print @_;
}
__END__