Results 1 to 17 of 17

Thread: Need help from someone who knows Perl

  1. #1
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747

    Need help from someone who knows Perl

    sub getEpochSeconds {
    my $TIMEVAL_T = "LL"; # LL for microseconds
    my $start = pack($TIMEVAL_T, ());
    syscall(&SYS_gettimeofday, $start, 0) != -1 or die "seconds: $!";
    return( (unpack($TIMEVAL_T, $start))[0] );
    }

    For some odd reason when i execute my script I get an error on the syscall() line:

    seconds: Invalid argument at line 79

    Any ideas?
    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

  2. #2
    Administrator Bok's Avatar
    Join Date
    Oct 2003
    Location
    Wake Forest, North Carolina, United States
    Posts
    24,468
    Blog Entries
    13
    try

    sub getEpochSeconds {
    my $TIMEVAL_T = "LL"; # LL for microseconds
    my $start = pack($TIMEVAL_T, ());
    syscall(&main::SYS_gettimeofday, $start, 0) != -1 or die "seconds: $!";
    return( (unpack($TIMEVAL_T, $start))[0] );
    }

  3. #3
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747
    No luck. It seems like it may be the die that's borking. When I take it out I get no error message. It also seems to see !$ as an invalid argument.
    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

  4. #4
    =>Team Joker<= LAURENU2's Avatar
    Join Date
    Dec 2004
    Location
    Chicago IL USA
    Posts
    5,478
    Blog Entries
    1
    Always Works For Me

  5. #5
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747
    Quote Originally Posted by LAURENU2
    Always Works For Me
    Very true...I won't have to see the error message again if I shatter my laptop in to it's own physical array.

    I'm beginning to think maybe there is an issue with the system call, but I don't believe so. I made sure I had syscall.ph available and I even recreated it by converting the syscall.h to syscall.ph again.

    I even isolated the code from the script and made a separate test script:

    Code:
    #! /usr/bin/perl -w
    require 'sys/syscall.ph';
    my $start = pack("LL", ());
    syscall(&SYS_gettimeofday, $start, 0) != -1 or die "seconds: $!";
    I still get the same error. I've tryed changing it the syscall line to:

    Code:
    syscall(&main::SYS_gettimeofday, $start, 0) != -1 or die $!;
    Same error message. I tried changing 0 to undef and same thing. If I changed it to:

    Code:
    syscall(&SYS_gettimeofday, $start, 0) != -1 or die;
    I get "Died at test.pl line 4. It seems to be an issue with die handling arguments?
    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

  6. #6
    Stats God in Training Darkness Productions's Avatar
    Join Date
    Dec 2001
    Location
    The land of dp!
    Posts
    4,164
    Does it have anything to do with the fact that your pack() isn't returning 'anything'?

  7. #7
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747
    Quote Originally Posted by Darkness Productions
    Does it have anything to do with the fact that your pack() isn't returning 'anything'?

    It does it regardless of what's going on with pack. The only thing my test script has now is:

    my $TIMEVAL_T = "LL"; # LL for microseconds
    my $start = pack($TIMEVAL_T, ());
    syscall(&SYS_gettimeofday, $start, 0) != -1 or die "seconds: $!";
    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

  8. #8
    Target Butt IronBits's Avatar
    Join Date
    Dec 2001
    Location
    Morrisville, NC
    Posts
    8,619
    Undefined subroutine &main::SYS_gettimeofday called at C:\test.pl line 3.

  9. #9
    Dungeon Master alpha's Avatar
    Join Date
    Mar 2002
    Location
    Norfolk, UK
    Posts
    1,700
    Works fine almost as it is on FreeBSD with perl 5.8.8, I just had to change "&SYS_gettimeofday" to "116" as detailed in syscall.ph (/usr/local/lib/perl5/site_perl/5.8.8/mach/sys/syscall.ph). It doesn't come up with any error regarding "seconds" when I run it.

    Though I agree with DP, it seems as though the pack call is setting $start to nothing.

  10. #10
    Stats God in Training Darkness Productions's Avatar
    Join Date
    Dec 2001
    Location
    The land of dp!
    Posts
    4,164
    mag:

    May I ask, what exactly are you trying to accomplish? Getting the number of microseconds from the epoch, on 64-bit hardware?

    From the information I can gather, that's what this is designed to do...

  11. #11
    Stats God in Training Darkness Productions's Avatar
    Join Date
    Dec 2001
    Location
    The land of dp!
    Posts
    4,164
    Actually, ignore that statement. What version of perl are you on?

  12. #12
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747
    Perl 5.8.8 is what I'm using (Ubuntu x86). I'm actually modifying a script to utilize the accelerometer in my Thinkpad to do usefull things when I bump it (using hdaps kernel module).

    Currently I just have a C script that rotates my Beryl desktop cube (original author's video) when I bump it to the right or left. It was originally written for Compiz, but I modified it to work with Beryl.

    I want to get this Perl script working though.

    I just posted that function, however there are multiple ones that just won't work in the same fashion. I figure if I can fix one I can fix them all. I posted the same question at PerlGuru.com and no one has even responded.
    Last edited by magnav0x; 07-10-2007 at 05:38 PM.
    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

  13. #13
    Stats God in Training Darkness Productions's Avatar
    Join Date
    Dec 2001
    Location
    The land of dp!
    Posts
    4,164
    The only reason I ask, is that I have the following (working!) script:


    Code:
    #!/usr/bin/perl -w
    
    require "sys/syscall.ph";
    
    $start = &getEpochSeconds();
    
    sleep(3);
    
    $done = &getEpochSeconds();
    $deltatime = sprintf("%.4f", ($done)-($start));
    print $deltatime;
    
    sub getEpochSeconds {
        my $TIMEVAL_T = "LL";
        my $timer = pack($TIMEVAL_T, ());
        syscall(&SYS_gettimeofday, $timer, 0) != -1 || die "gettimeofday: $!";
        return ((unpack($TIMEVAL_T, $timer))[0]);
    }

    on 5.8.8...

  14. #14
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747
    Quote Originally Posted by Darkness Productions
    The only reason I ask, is that I have the following (working!) script:


    Code:
    #!/usr/bin/perl -w
    
    require "sys/syscall.ph";
    
    $start = &getEpochSeconds();
    
    sleep(3);
    
    $done = &getEpochSeconds();
    $deltatime = sprintf("%.4f", ($done)-($start));
    print $deltatime;
    
    sub getEpochSeconds {
        my $TIMEVAL_T = "LL";
        my $timer = pack($TIMEVAL_T, ());
        syscall(&SYS_gettimeofday, $timer, 0) != -1 || die "gettimeofday: $!";
        return ((unpack($TIMEVAL_T, $timer))[0]);
    }

    on 5.8.8...
    What OS are you using? I'm wondering if something on my system is screwed (possibly my syscall.ph?). I've Googled until my fingers started to bleed and I found nothing similar to my issue.
    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

  15. #15
    Member
    Join Date
    Sep 2006
    Location
    North Carolina USA
    Posts
    54
    They maybe able to help here also. http://tek-tips.com/threadminder.cfm?pid=219 it is a Perl forum
    Life is Just a Big Role Playing Adventure

  16. #16
    Stats Developer magnav0x's Avatar
    Join Date
    Mar 2002
    Location
    Dallas, TX
    Posts
    1,747
    Quote Originally Posted by Sleepsalot
    They maybe able to help here also. http://tek-tips.com/threadminder.cfm?pid=219 it is a Perl forum
    Thanks for the link. I'll give them a go.
    Warning this Post is Rated "M" for Mature

    -Contains Harsh Language
    -L337 HaX0r W3RD2!
    -Partial Nudity

    I haven't lost my mind; it's backed up on tape drive somewhere.

  17. #17
    Stats God in Training Darkness Productions's Avatar
    Join Date
    Dec 2001
    Location
    The land of dp!
    Posts
    4,164
    On debian testing...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •