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

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Read the config file and create the INVITE line as per config file
by davorg (Chancellor) on Aug 17, 2006 at 10:10 UTC

    When you previewed that node, the website gave you a message that said:

    If something looked unlike you expected it to you might need to check out Writeup Formatting Tips

    Did the preview really look how you wanted it to look? The formatting of you input file is really very important if you want people to help you parse it. It would make it far easier to help you if you took the trouble to make sure that the formatting was accurate.

    Or perhaps you didn't preview the node. You were in such a hurry that you pressed "create" rather than "preview". Hopefully you can now see why that's a bad idea :-)

    (For anyone reading after the inevitable editor's clean-up - the node originally had no <code> tags and therefore everything ran together on one line)

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Read the config file and create the INVITE line as per config file
by lima1 (Curate) on Aug 17, 2006 at 10:08 UTC
    use strict; use warnings; use Config::Tiny; my $DATA =<<EOT localusername=me ip=36.212.176.90 port=5060 remotename=you ip=36.212.176.92 port=5060 transport=udp EOT ; # Create a config my $Config = Config::Tiny->new(); # Open the config, replace with read and $DATA with filename $Config = Config::Tiny->read_string( $DATA ); #$Config = Config::Tiny->read( $filename ); # see perldoc Config::Tiny my $s = $Config->{_}; # I was to lazy to finish this: my $INVITE = join(' ', 'INVITE sip:' . $s->{remotename} .'@'. $s->{ip} +, 'SIP/2.0 Via:SIP/2.0/UDP', $s->{localusername} +. '@' . $s->{ip} .':5060', 'From:sam<sip:me@36.212.176.92>', 'To: you<sip:you@36.212.176.90>', ); print $INVITE;
    UPDATE: You probably want to add a [local] and a [remote] section in the config file. Then just access the variables with $r = Config->{remote} and build your INVITE line. See perldoc Config::Tiny.