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> <<a href="mailto:davidnicol@gmail.com">davidnicol@gmail.com</a>> 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 <<a href="mailto:lokeey@gmail.com">lokeey@gmail.com</a>> wrote:<br>> Sorry, the NEC is the device...and it's dealing with the ADM's (add drop
<br>> multiplexer) basically, i just need to log in, and run some rtrv commands<br>> using the specified CLLI code that is given.<br>><br>> its about 900 or so CLLI codes and i'm not 100% sure how to write the
<br>> script.<br><br>okay. 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. 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> while(defined($response = readresponse(S))){<br> $command = $statefulobject->handle($response);<br> sendcommand(S,$command);<br> };<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> # you can now do $object->T_T_P("reading2") for instance<br> sub TRANSITION_TO_PACKAGE{ bless $_[0], $_[1] };<br></blockquote></div><br><br clear="all"><br>-- <br>99 years and counting!