Question: Convert this shell script to PERL script. This is the shell script and I need it to be written as perl program # Check to

Convert this shell script to PERL script. This is the shell script and I need it to be written as perl program

# Check to make sure the input file was passed as a parameter

if [ $# -ne 1 ]; then

echo "usage: $0 "

exit 1

fi

# Compute the average of the parameters passed in

function computeAvgNum {

avg=0

# iterate over parameters, adding them together

for val in "$@"

do

avg=$(echo "scale=2; $avg + $val" | bc)

done

# divide but the number of parameters

avg=$(echo "scale=2; $avg / $#" | bc)

echo "$avg"

}

echo "Performance Data"

# Iterate over our data file storing our values

while read code value; do

# Output our content

case "$code" in

D) echo "Date " $(echo $value | cut -f1 -d' ') ;;

B) echo "Tamb (C) " $(computeAvgNum $value) ;;

P) echo "Tref (C) " $(computeAvgNum $value) ;;

Q) echo "Tm (C) " $(computeAvgNum $value) ;;

R) echo "Irradiance (W/m^2) " $(computeAvgNum $value) ;;

H) echo "Isc (A) " $(computeAvgNum $value) ;;

O) echo "Voc (V) " $(computeAvgNum $value) ;;

C) echo "Imp (A) " $(computeAvgNum $value) ;;

K) echo "Vmp (V) " $(computeAvgNum $value) ;;

W) echo "Pm (W) " $(computeAvgNum $value) ;;

L) echo "FF (%) " $(computeAvgNum $value) ;;

esac

done <$1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!