thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Although that this question should have a simple answer I can not understand where I am going wrong. I am using a Linux OS and I executing the following part of code:

#!/usr/bin/perl use strict; use warnings; use Time::HiRes qw( clock_gettime clock_getres ); my $realtime = clock_gettime('CLOCK_REALTIME'); my $resolution = clock_getres('CLOCK_REALTIME'); print "Realtime: ".$realtime."\n"; print "Resolution: ".$resolution."\n";

I am getting this error:

Argument "CLOCK_REALTIME" isn't numeric in subroutine entry at test.pl + line 6. Argument "CLOCK_REALTIME" isn't numeric in subroutine entry at test.pl + line 7. Realtime: 1411038919.69833 Resolution: 1e-09

According to Time::HiRes the syntax should not include the single quotes and it should be modified accordingly:

#!/usr/bin/perl use strict; use warnings; use Time::HiRes qw( clock_gettime clock_getres ); my $realtime = clock_gettime(CLOCK_REALTIME); my $resolution = clock_getres(CLOCK_REALTIME); print "Realtime: ".$realtime."\n"; print "Resolution: ".$resolution."\n";

But I get the following error when I execute the code:

Bareword "CLOCK_REALTIME" not allowed while "strict subs" in use at te +st.pl line 6. Bareword "CLOCK_REALTIME" not allowed while "strict subs" in use at te +st.pl line 7. Execution of test.pl aborted due to compilation errors.

Any ideas why I am getting this error on both cases?

Thank you in advance for your time and effort to assist me.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re: Argument "CLOCK_REALTIME" isn't numeric in subroutine entry
by Corion (Patriarch) on Sep 18, 2014 at 11:18 UTC

    You will need to import CLOCK_REALTIME too:

    use Time::HiRes qw( clock_gettime clock_getres CLOCK_REALTIME );

    Also see the EXAMPLES section of Time::HiRes, where the correct import is shown.

      Hello Corion,

      OMG!!!! So simple and I was thinking about it. I did not scroll the page to the bottom to see that. Sometimes the answer is so simple.

      Thank you for your time and effort, quick question in case you know the answer. Those two commands are also compatible in Windows and MAC OS's?

      I am developing a sample of code and I am looking for compatibility with all OS environments.

      Seeking for Perl wisdom...on the process of learning...not there...yet!