My program is such that it first reads the file imp2.txt and stores it in a array.According to the flow of requests and responses it goes to the send block for sending messages or goes to the receive block for receiving the responses from the server. Actually i am using goto for it. But suggest me some more decent way for doing it.
use IO::Socket::INET; use strict; use Config::Tiny; use Config::Random; my ($DATA,$text,$msg, $array1); my @array; open TESTCASE, "imp2.txt" or die $!; while(<TESTCASE>) { $array1 = $_; chomp $array1; $array[$incre]= $array1; $incre++; } open CONFIGFILE, "imp1.txt" or die $!; { local $/; $/ = undef; $DATA=<CONFIGFILE>; } my $Config = Config::ACTI->new(); $Config = Config::ACTI->read_string( $DATA ); $s = $Config->{_}; my $method= <<END; REGISTER sip: 36.212.176.07 SIP/2.0\r Via: SIP/2.0/UDP 36.212.176.90:5060; branch= z9hg4bk340\r To: sanjay<sip:userA@36.212.176.90>\r From:sanjay<sip:userA@36.212.176.90>;tag= abcd1250\r Max-Forwards: 70\r Call-ID: abchjhg1560@36.212.176.90\r CSeq: 1 REGISTER\r Contact:sanjay<sip:userA@36.212.176.90>; expires=7200\r Content-Length:0\r \r END my $MySocket=new IO::Socket::INET->new( LocalAddr=>$s->{Local_IP}, LocalPort=>$s->{LocalPort}, PeerPort=>$s->{RemotePort}, Proto=>$s->{Transport}, PeerAddr=>$s->{Remote_IP} ); $MySocket or die "no socket :$!"; print "\nClient Started: Ready For Packet To Send:\n"; my $incre = 0; COND:for(;;) { last if $array[$incr] eq ''; if ($array[$incr] eq "[SEND]") { $incr++; if ($array[$incr] eq ("REGISTER" || "INVITE" || "ACK" || "BYE" || + "OPTION" || "CANCEL")) { $incr++; goto OUTER; } else { print "Bad Request :$array[$incr]"; exit 1; } } elsif ($array[$incr] eq "[RECV]") { $incr++; if($array[$incr] == (100 || 200 || 300 || 400)) { $incr++; goto INNER; } else { print "Bad Response name:$array[$incr]"; exit 1; } } else { print "Bare word found:"; exit 1; } } OUTER:for(;;) { my $msg=$method; print "\nSending message:$msg"; $MySocket->send($msg); goto COND; } INNER:for(;;) { print "Waiting for Response:\n"; $MySocket->recv ($text,1000);#///Recv print "\nReceived message From:$text"; goto COND; }
The imp1.txt contains
Remote_IP=36.212.176.07
RemotePort=5060
Local_IP=36.212.176.90
LocalPort=5060
Transport=udp
The imp2.txt contains
[SEND] REGISTER [RECV] 100 [RECV] 200

2006-08-30 Retitled by holli, as per Monastery guidelines
Original title: 'plz, suggest me any suitable code for it???'

Edited by planetscape - added readmore tags

( keep:0 edit:15 reap:0 )


In reply to How to replace 'goto' by another construct? by sanjay nayak

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.