panchanan
panchanan

Reputation: 192

How to compare two variable. one is perl variable and another is python variable

I am getting one output from perl subroutine and another output from python function.

I want to compare these two variables so that I can conclude both outputs are same.

ex-python function

#!usr/bin/lib/python
import os,sys
def sub(a, b):
   e= a-b
   return e

   #calling function
   p = sub(9,2)
   print "value of P:%s" %p

o/p value of p : 7

perl subroutine---

#!/usr/bin/perl
my $average;
sub Average{
   $n = scalar(@_);
   $sum = 0;

   foreach $item (@_){
      $sum += $item;
      }
      $average = $sum / $n;
      return $average;
      }

 #calling subroutine
 $average = Average(11,3);
 print "my avearage : $average";

o/p my avarage: 7

since this is two different language, I am facing problem in comparing p value with average.

Upvotes: 1

Views: 121

Answers (1)

Barmar
Barmar

Reputation: 781105

Call the programs from the shell, strip off the words before the numbers, and compare them:

python_result=$(python_prog)
perl_result=$(perl_prog)
perl_result
if [ "${python_result#*:}" = "${perl_result#*: }" ]
then echo They match
else echo No match
fi

Upvotes: 3

Related Questions