I tried using this script to test if the array would take the values but it didnt.
#!/usr/bin/perl
$str="a few numbers are 41, 32, and 56.";
$str1=$str;
$str1=~ s/\D*(\d+)\D*(\d+)\D*(\d+)/$1--$2--$3/;
#this part didnt work out
@array=($1, $2, $3);
print $array[3];
I was wondering if I could get some helpful answers thanks!
$ cat avg.pl
#!/usr/bin/perl
use strict;
my $line;
my $val;
my $school;
my $grades;
my $score;
my $total;
my $avg;
my $i;
open ( INFILE, "<avg.dat" ) or
die "ERROR: Unable to open file: avg.dat" ;
while ($line = <INFILE>) {
chomp $line;
($school,$grades) = split(' ', $line, 2);
$i = 0;
$total = 0;
foreach $score (split(',', $grades)) {
$i++;
$total += $score;
}
$avg = $total/$i;
printf "%s: %.1f\n", $school, $avg;
}
close (INFILE);
exit;