PDA

View Full Version : weird perl


GunshotSilence
26-10-2005, 12:28 AM
i wrote this code to find the nCr of a no. in perl 5 in windows.

i have used subroutines. but since i used it for first time(specified in college assignemnt ) i im very good with it. any way, the program ran properly in windows.

now when i typed the code in our college ( clients on windows 98 connect to server on redhat 8 thru puttry telnet tool-perl there too is version 5.xx)
it simply didnt budge. someone said subroutine isnt returning value. so made necesarry changes and sat for 3 hrs but program just didnt run.

when i run the same program(whihc wrote at home in windows perl) in mandrake 10.1 at home, it runs and no errors too. SO WHY DIDNT IT RUN IN RED HAT 8 IN COLLEGE.

SAVE THIS CODE in notepad as ncr.pl and in console(dos or linux)

note: give values in command line while running
ex:
type at prompt ($) perl ncr.pl 12 8

to find 12C8

remove the first line if running in windows




#! /usr/bin/perl
system "clear";

print "\nProgram Name=> nCr \n";

$n=$ARGV[0];

$r=$ARGV[1];
chomp $n;
chomp $r;

if($n<$r || $n<0 || $r<0)
{
print "\n U MORON, n cannot be < r or -ve. Enter again\n";
}

else
{
print "\n n= $n\n";
print "\n r= $r\n";

$nfact=1;

$rfact=1;

$nrfact=1;


&fact($n,$r);

print "\n n!= $nfact\n";

print "\n r!= $rfact\n";

print "\n (n-r)!= $nrfact\n";

$l=$rfact*$nrfact;

print "\n r!*(n-r)!= $l\n";

$m=$nfact/$l;

print "\n Formula for nCr=n!/(r!*(n-r)!) \n";
print "\n nCr=$n!/($r!*($n-$r)!)=$m \n";
}



sub fact
{

for($i=1;$i<=$n;$i++)

{

$nfact*=$i;

}



for($j=1;$j<=$r;$j++)

{

$rfact*=$j;

}



for($k=1;$k<=($n-$r);$k++)

{

$nrfact*=$k;

}

}


PLZ HELP ME

desertwind
26-10-2005, 02:19 AM
It is working fine on my FC4 box.
http://www.iup.in/out.php/t33_Screenshot.png (http://www.iup.in/show.php/33_Screenshot.png)

so what is the error u getting on RH8, and please post the perl version on RH8

GunshotSilence
26-10-2005, 10:23 PM
well after running on RH8 it showed

n=12
r=8

thats it

nothing else.

but same program on mandrake is running fine.

desertwind
28-10-2005, 11:09 PM
Sometimes different versions may create problems. I really had a hard time compiling audioscrobbler plugin for rhythmbox in FC4 which uses python 2.4. but it worked fine when compiled using python 2.3. Thats why i asked for the perl compiler version on RH8. RH8 is pretty old. so u may having a old compiler. try upgrading the compiler.