Home > Archive > General Discussion > May 2001 > Silly Perl Prob





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Silly Perl Prob
Randy

2001-05-30, 10:38 am

Does anyone know how to extract square roots in Perl?

I tried:

$sqrt = $number ** (0.5);

but it doesn't seem to understand decimal exponents. For example, when initialising $number to 4, $sqrt evaluates to 1! Anybody have any ideas?
Randy

2001-05-31, 12:57 pm

OK, in case anyone was wondering, let me answer my own question. Actually, what I had typed in my script was not:

$sqrt = $number ** (0.5);

as I had mentioned, but:

$square_rt = $number ** (0.5);

which turned out to be a good thing since sqrt is a function, and I would have gotten an error. It seems as though Perl doesn't like decimal exponents, at least from what I can tell, as it returns false values, but the sqrt(); function seems to do the trick for square roots anyway.
creamy_stew

2001-05-31, 6:11 pm

Read this and weep!

quote:

C:\WINDOWS>more kaka.pl

$kaka = 4 ** (0.5);
print $kaka;


C:\WINDOWS>perl kaka.pl
2
C:\WINDOWS>



Active perl 0wnz j00

/creamy
Randy

2001-05-31, 6:38 pm

My name is mud. That worked . . . I wonder what I was doing wrong above? BTW, my file was in /home/gsibbery, and not C:\ . . . thanks, though.
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net