G'day Konan,

Welcome to the Monastery.

[Disclaimer: I am not a user of Device::BCM2835. The following is based on its source code.]

gpio_fsel() is not exported; however, you can create an alias so that you don't need to use the fully-qualified subroutine name repeatedly (see "perldata: Typeglobs and Filehandles" for details):

*gpio_fsel = \&Device::BCM2835::gpio_fsel;

RPI_V2_GPIO_P1_07 is exported (line 582); it's part of our @EXPORT = qw(...); which starts on line 317.

Your code could end up looking something like this:

#!/usr/bin/env perl use strict; use warnings; use Device::BCM2835; ... *gpio_fsel = \&Device::BCM2835::gpio_fsel; ... my $inputcmd = ...; ... gpio_fsel(RPI_V2_GPIO_P1_07, $inputcmd); ...

To use a variable in place of RPI_V2_GPIO_P1_07, you could do something like the following. Bear in mind, without seeing your code, I'm very much guessing with regards to the context.

my %rpi_v2_gpio_p1 = ( 3 => RPI_V2_GPIO_P1_03, 5 => RPI_V2_GPIO_P1_05, 7 => RPI_V2_GPIO_P1_07, ..., 40 => RPI_V2_GPIO_P1_40, ); ... gpio_fsel($rpi_v2_gpio_p1{$_}, $inputcmd) for 3, 5, 7, ..., 40;

In other posts, I see variations using dispatch tables and eval. These may well be more appropriate for your code.

If none of the suggestions so far are suitable, you'll need to show us more code such that we can see how gpio_fsel() is being used.

— Ken


In reply to Re: How to make a variable in hard call. by kcott
in thread How to make a variable in hard call. by Konan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.