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
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Perl script help

  • 14-05-2012 12:43AM
    #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: 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