Frequency analysis for simultaneous dice rolls - follow-up I had another question for my Perl class assignment.

Related question:

Frequency analysis for simultaneous dice rolls

use warnings;                
use diagnostics;
use GD::Graph::hbars;
use List::Util qw(max);
my $number_of_dice=0;
my $number_of_rolls=0;
my @total_sum_of_eyes;
my %count;
my $counter=0;

print "\n Please insert the number_of_dice: ";
chomp($number_of_dice=&lt;STDIN&gt;);
print "\n Please instert the number_of_rolls: ";
chomp($number_of_rolls=&lt;STDIN&gt;);

while ($counter&lt; $number_of_rolls){
    push(@total_sum_of_eyes,roll($number_of_dice));
    $counter++;
}  
frequency(@total_sum_of_eyes);
representation(%count);

sub roll{
    my $number=0;
    my $sum_of_throw=0;
    $sum_of_throw = 0;
    for($i=0;$i&lt;$number_of_dice;$i++){
        $number = int(rand(6) +1);
        $sum_of_throw+=$number;
    }
    return $sum_of_throw;
}
sub frequency{

    for($i=0;$i&lt;$number_of_rolls;$i++){
        $count{$total_sum_of_eyes[$i]}++;
    }
    return;
}
sub representation{
    my @single_sum_of_eyes;
    my @frequency;
    print "\n the frequencys-distribution is: \n";
    print "\n total_sum_of_eyes\t frequency\t frequencys-distribution in %\n";
    foreach my $eyes (sort{$a &lt;=&gt; $b} keys %count){
        push(@frequency, $count{$eyes});
        push(@single_sum_of_eyes, $eyes);
        printf "\n\t $eyes\t\t\t  $count{$eyes}\t\t%g",($count{$eyes}/$number_of_rolls)*100;
    }
    print "\n";
    my $graph = GD::Graph::hbars-&gt;new(1600, 600);
$graph-&gt;set(
    x_label             =&gt; 'total_sum_of_eyes',
    y_label             =&gt; 'frequency',
    title               =&gt; 'frequencys-distribution',
    y_max_value         =&gt;  max(@frequency)+1,
    y_tick_number       =&gt; 8,
    transparent         =&gt; 0,
    long_ticks          =&gt; 1,
) or die $graph-&gt;error;
my @data = (\@single_sum_of_eyes,\@frequency);
$graph-&gt;set( dclrs =&gt; [ qw(green) ] );
my $gd = $graph-&gt;plot(\@data) or die $graph-&gt;error;
open(IMG, '&gt;gd_bars.gif') or die $!;
binmode IMG;
print IMG $gd-&gt;gif;
return;
}



frequency(@total_sum_of_eyes);
representation(%count);


Is this necessary?

foreach my $eyes (sort{$a &lt;=&gt; $b} keys %count){
        push(@frequency, $count{$eyes});
        push(@single_sum_of_eyes, $eyes);
        printf "\n\t $eyes\t\t\t  $count{$eyes}\t\t%g",($count{$eyes}/$number_of_rolls)*100;
    }


I can't seem to find a simple for-loop for this one.
Found a solution without foreach 

@single_sum_of_eyes = sort{$a &lt;=&gt; $b} keys %count;
    for($j = 0; $j&lt;scalar @single_sum_of_eyes; $j++)
    {
        push(@frequency,$count{$single_sum_of_eyes[$j]});
    }
    for($i=0; $i&lt;scalar @frequency; $i++)
    {
    printf "\n\t$single_sum_of_eyes[$i]\t\t\t $frequency[$i]\t\t%g", ($frequency[$i]/$number_of_rolls)*100;
    }
    print "\n";