http://www.perlmonks.org?node_id=995056


in reply to Re: Help with arrays
in thread Help with arrays

I think I Finally figured it out =)
#!/usr/bin/perl use warnings; $sum = 0; @nums = (); push (@nums,(4,4)); $sum += $_ for @nums; $size = @nums; $average = $sum / $size; print "$average";
This worked I am not sure if it's the correct way but it gave me the average

Replies are listed 'Best First'.
Re^3: Help with arrays
by Kenosis (Priest) on Sep 22, 2012 at 06:37 UTC

    Yes--well done!

    ...I am not sure if it's the correct way...

    Tim Toady!

    If I may, however, offer the following for you to consider:

    #!/usr/bin/perl use strict; use warnings; my $sum = 0; my @nums = (); push( @nums, ( 4, 8 ) ); $sum += $_ for @nums; my $size = @nums; my $average = $sum / $size; print "$average";
Re^3: Help with arrays
by Kenosis (Priest) on Sep 22, 2012 at 06:42 UTC

    My error...re-posted the above message.