Home > Archive > PERL Beginners > November 2007 > Trying to use Floor
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 |
Trying to use Floor
|
|
| Thomas F. Droege 2007-11-18, 7:00 pm |
| Trying to use floor:
[tom@tom3 test]$ /home/tom/mk4/perl/test_floor.pl
enter a number to be floored 3.557
Undefined subroutine &main::floor called at
/home/tom/mk4/perl/test_floor.pl line 8, <> line 1.
[tom@tom3 test]$
Here is the code:
#!/usr/bin/perl -w
use strict;
use warnings;
my $foo = 0;
my $goo = 0;
print "enter a number to be floored ";
$foo = <>;
$goo = floor($foo);
print "floor is $goo \n";
0) My first post here - please correct me if I am not using correctly
I am an engineer not a professional programmer so please don't tell
me you do it just like in c. (an answer I often see in the doc)
1) I suspect a version problem since search indicates floor added after
5.0
How do I ask perl what version is installed?
2) I am running Mandriva 2006 on an Intel 64 bit dual, dual (very nice).
Running somewhat older version of Mandriva because I know it's bugs.
3) How would I download later version of perl if that is needed?
4) Looking at CPAN I see that math.ops has what I need. How do I add
math.ops to my program? I am a real beginner so I would need details.
Thank you people for doing this work. If I knew what I know now, I
would
be trying to hire some of you to set up stuff to develop physics
instrumentation. Still might get someone else to use perl for this
purpose. Would this be the right place to start finding help?
--
Thomas F. Droege
droege@fastmail.fm
| |
| Chas. Owens 2007-11-18, 10:00 pm |
| On Nov 18, 2007 7:32 PM, Thomas F. Droege <droege@fastmail.fm> wrote:
> Trying to use floor:
snip
The ceil and floor functions are defined in the POSIX module. Read
"perldoc -q floor" for more info.
#!/usr/bin/perl
use strict;
use warnings; #don't use -w if you are going to use the warnings
pragma, it is redundant
use POSIX;
#use line terminators, otherwise you might not see the prompt due to buffering
print "enter a number to be floored\n";
#define variables as late as possible and avoid initializing them with data
#you plan to through away (undef values are very useful in debugging)
my $foo = <>;
my $goo = floor($foo);
print "floor is $goo\n";
snip
0) My first post here - please correct me if I am not using correctly
I am an engineer not a professional programmer so please don't tell
me you do it just like in c. (an answer I often see in the doc)
snip
Seems fine to me.
snip
1) I suspect a version problem since search indicates floor added after
5.0
How do I ask perl what version is installed?
snip
Not an version problem, they just aren't exported by default (you need
to use the POSIX module), but you can get the version of Perl by
saying
perl -v
The current version is 5.8.8 with 5.10 coming out real soon (5.9, like
all odd middle digit version numbers in Perl, is a development
version).
snip
2) I am running Mandriva 2006 on an Intel 64 bit dual, dual (very nice).
Running somewhat older version of Mandriva because I know it's bugs.
snip
You most likely have a version of 5.8 installed.
snip
3) How would I download later version of perl if that is needed?
snip
In general you should use the package system your OS provides (in
Mandriva's case this is RPM/YUM). If you absolutely had to have the
latest and greatest version of Perl you could download the source for
perl.org and compile it (it is not very difficult), but using the
package system is preferable.
snip
4) Looking at CPAN I see that math.ops has what I need. How do I add
math.ops to my program? I am a real beginner so I would need details.
snip
I doubt you found a module named math.ops (I don't think it is a valid
module name). A quick search on CPAN shows that math.ops is part of
Parrot (an experimental virtual machine associated with the equally
highly experimental Perl 6) not Perl. If you had found a module that
you needed to install (not part of Core Perl like POSIX), you would
have had three options (in order of preference):
1. install through your package manager:
yum install foo-bar.rpm
foo-bar often fits a pattern. Ubuntu's pattern is given Foo::Bar the
package name will be libfoo-bar-perl.deb. Mandriva's seems to be
something like perl-Foo-Bar-versioninfo.rpm.
2. install using CPAN
If you have a recent enough version of Perl you can say:
cpan install Foo::Bar
otherwise you will have to do it the old school way:
perl -MCPAN install Foo::Bar
3. install it manually
download the tar ball from cpan.org
decompress it
change directory into the resulting directory
type "perl Makefile.PL"
type "make"
type "make test"
ensure that none of the tests failed
type "sudo make install"
| |
| John W . Krahn 2007-11-19, 4:02 am |
| On Sunday 18 November 2007 17:12, Chas. Owens wrote:
>
> On Nov 18, 2007 7:32 PM, Thomas F. Droege <droege@fastmail.fm> wrote:
>
>
> Not an version problem, they just aren't exported by default (you
> need to use the POSIX module), but you can get the version of Perl by
> saying
>
> perl -v
>
> The current version is 5.8.8 with 5.10 coming out real soon (5.9,
> like all odd middle digit version numbers in Perl, is a development
> version).
Not *all* middle digit version numbers. They only started doing that
in 2000 when 5.7.0 was introduced.
http://perldoc.perl.org/perlhist.html
John
--
use Perl;
program
fulfillment
|
|
|
|
|