daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Jun 19th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. #use warnings;
  3. #use strict;
  4. use 5.010;
  5.  
  6. running_sum(5, 6);
  7. running_sum(1..3);
  8. running_sum( 4 );
  9.  
  10. sub running_sum {
  11.     state $sum = 0;
  12.     state @numbers;
  13.    
  14.     foreach my $number ( @_ ) {
  15.         push (@numbers, $number);
  16.        
  17.         $sum += $number;
  18.     }
  19.     say "The sum of (@numbers) is $sum";
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top