sub sell { my ($portfolio, $ticker) = @_; my $stock_to_sell = query_user(q|What Stock would you like to Sell? |); my $cash = 0; foreach my $stock ( keys %$portfolio ) { if ( $stock =~ /$stock_to_sell/i ) {; if ( $$ticker{$stock}{price} == 0 ) { notify_user( qq|$stock has filed for protection from creditors|, q| - Your holdings were liquidated.| ); } else { my $shares_to_sell = query_user( qq|\n\nYou have $portfolio{$stock} shares in $stock\n|, q|Sell How many? :| ); if ( $shares_to_sell > $$portfolio{$stock} ) { notify_user( qq|Sorry, your account is not set |, qq|up for short selling.\n| ); } else { $$portfolio{$stock} -= $shares_to_sell; $cash = $shares_to_sell * $$ticker{$stock}{price}; } } last; } } return $cash; }