Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Perl script help

  • 13-05-2012 11:43pm
    #1
    Registered Users, Registered Users 2 Posts: 760 ✭✭✭


    Hey i need some help with a perl script.I've done some perl most was stuff with databases.

    when I run the below script the output is HASH(0x87076f0)

    How to do I convert in to a decimal vaule

    I've tried %us, @us instead of $us.

    http://search.cpan.org/~collins/LEGO-NXT-2.00-1/lib/LEGO/NXT.pm


    
    #!/bin/perl
    
    use LEGO::NXT;
    use LEGO::NXT::BlueComm;
    use LEGO::NXT::Constants qw(:DEFAULT);
    use Data::Dumper;
    use Net::Bluetooth;
    
    
    
    $nxt = LEGO::NXT->new( new LEGO::NXT::BlueComm('00:16:53:02:77:E0',2));
    $nxt->initialize_ultrasound_port($NXT_SENSOR_4);
    $us=$nxt->get_ultrasound_measurement_units($NXT_SENSOR_4);
    
    
    print ("\n");
    print( "vaule\t",$us);
    
    


Comments

  • Registered Users, Registered Users 2 Posts: 5,246 ✭✭✭conor.hogan.2




  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    HASH(0x87076f0)
    
    is a hash reference.

    I don't know the LEGO modules but I'd recommend reading the docs for the return value of the LEGO::NXT->get_ultrasound_measurement_units() method.
    perldoc LEGO::NXT
    
    should provide you with a man page style descrition of the API the module provides.

    Alternatively you can examine the data structure held in $us with Data::Dumper (which you have loaded already ;) )
    #!/bin/perl
    use strict;
    use warnings;
    
    use LEGO::NXT;
    use LEGO::NXT::BlueComm;
    use LEGO::NXT::Constants qw(:DEFAULT);
    use Data::Dumper;
    use Net::Bluetooth;
    
    my $nxt = LEGO::NXT->new( new LEGO::NXT::BlueComm('00:16:53:02:77:E0',2));
    $nxt->initialize_ultrasound_port($NXT_SENSOR_4);
    my $us=$nxt->get_ultrasound_measurement_units($NXT_SENSOR_4);
    
    print Dumper($us);
    
    As a general rule using strict and warnings is also worthwhile as it catches a lot of common errors.


  • Registered Users, Registered Users 2 Posts: 760 ✭✭✭mach1982


    Thanks all, I fell real stupid just check the authors page , the link is on cpan module page

    http://nxt.ivorycity.com/

    and the code is there .


    *bangs head against wall*

    Ouch that hunt


Advertisement