Sombrerero_loco has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks. Im doing a really weird program and i need to use Device::Modem::Gsm, to read the imei and make a ln on /dev. Ok, the problem is, i need to pass this to the constructor, but i dont wanna to hardcode every modem i want to have, i want to read a dir, parse the modems and try to connect to this modems.
use Device::Gsm; my $gsm = new Device::Gsm( port => '/dev/ttyS1', pin => 'xxxx' ); if( $gsm->connect() ) { print "connected!\n"; } else { print "sorry, no connection with gsm phone on serial port!\n"; }
Where it says '/dev/ttyS1' i need to put a $variable, but it doesnt read the variable, :( Any workaround or i should mess with the AT commands ? thanks!

Replies are listed 'Best First'.
Re: Any idea how to pass a variable there ?
by davido (Cardinal) on Jun 25, 2013 at 16:09 UTC

    Single quotes don't interpolate. Use double-quotes so that you get variable interpolation. Or no quotes at all if a variable by itself contains the entire field.

    my $gsm = new Device::Gsm( port => $variable ....

    ...or...

    my $gsm = new Device::Gsm( port => "stuff/plus/$interoplation"...

    Dave

Re: Any idea how to pass a variable there ?
by LanX (Saint) on Jun 25, 2013 at 16:08 UTC
    > Where it says '/dev/ttyS1' i need to put a $variable, but it doesnt read the variable

    Thats impossible!¹

    Your problem is somewhere else, but w/o showing us more we can't tell a lot!

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    update

    ¹) But davido's guess is not bad! =)