in reply to How to make a variable in hard call.
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to make a variable in hard call.
by ikegami (Patriarch) on May 09, 2023 at 08:20 UTC | |
by cavac (Prior) on May 11, 2023 at 09:03 UTC | |
|
Re^2: How to make a variable in hard call.
by kcott (Archbishop) on May 09, 2023 at 12:53 UTC | |
by Anonymous Monk on May 09, 2023 at 13:32 UTC |