i've done the expect scripts for less complex stuff...i figured i'd try doing it with perl this time around since there is much more to it.<br><br>
<div><span class="gmail_quote">On 11/16/06, <b class="gmail_sendername">David Nicol</b> &lt;<a href="mailto:davidnicol@gmail.com">davidnicol@gmail.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On 11/16/06, Lokeey &lt;<a href="mailto:lokeey@gmail.com">lokeey@gmail.com</a>&gt; wrote:<br>&gt; Sorry, the NEC is the device...and it's dealing with the ADM's (add drop
<br>&gt; multiplexer) basically, i just need to log in, and run some rtrv commands<br>&gt; using the specified CLLI code that is given.<br>&gt;<br>&gt; its about 900 or so CLLI codes and i'm not 100% sure how to write the
<br>&gt; script.<br><br>okay.&nbsp;&nbsp;You have a little language, and the responses need to be more<br>complex than can be implemented with a tool like GNU expect.<br><br>First, you establish to connection, by opening a socket and connecting
<br>it to your device, then do what you have to to log in.<br><br>Oh -- before you even do that, or while your assistant is doing that, draw<br>a state diagram of what you want to have happen during the interaction,<br>and a list of possible responses and possible commands in each state.
<br><br>Make a separate package for each state.&nbsp;&nbsp;the packages can inherit<br>from each other if that makes sense, if there are two states that<br>are very similar.<br><br>In your main program that made the connection and logged in on
<br>socket S, do something like<br><br>&nbsp;&nbsp;&nbsp;&nbsp; while(defined($response = readresponse(S))){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $command = $statefulobject-&gt;handle($response);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sendcommand(S,$command);<br>&nbsp;&nbsp;&nbsp;&nbsp; };<br><br>this approach will work with multiple scripts running simultaneously
<br>on different sockets each associated with its own stateful object, in<br>a select() loop, but that's overengineering for what you're doing i think.<br><br>Stateful objects can change their state by transitioning with bless()
<br><br>&nbsp;&nbsp;# you can now do $object-&gt;T_T_P(&quot;reading2&quot;) for instance<br>&nbsp;&nbsp;sub TRANSITION_TO_PACKAGE{ bless $_[0], $_[1] };<br></blockquote></div><br><br clear="all"><br>-- <br>99 years and counting!