telnet chars and chat regexs 
Author Message
 telnet chars and chat regexs

Hi all, 2 questions:

I need a regex to match EVERYTHING.
The data I am matching to can contain anything even lots of \n's

I have set $*=1;,

I am using it as a regex in the &expect routine of chat2

Currently, all that works is

'(.|\n)' to match one character, because
'(.|\n)*' does not match ANY
yet
'(.|\n)+' does exactly what I want - NOW if * is greedy, what changed its
mind...

The other (trvial) [ho ho] matter concerns character interpretation of
telnet.  I took a gander at the RFS's but they are many, and I supposed if
someone knew the answer, they would not mind churning it out.

I made socket, and with some machiner, connetc it to a shell.

I can telnet to the socket; but, when the telnet is running in character
mode, it does not start new lines properly, the shell sends \012,
but this is not enough for the telnet, so I convert all \012
to be \012\015 and all is well - NOT because then I muck up some escape
sequences...

Now when I tell telnet (via "mode character" command) to do
character-at-a-time it sends off a control string which my shell (of course)
doesn't interpret.  It also seems that telnet expects a reply (which I don't
supply)

It could be this which is mucking it up, however, presently I am stuck in
the worl of line-by-line telnet.

Oh help.....

Oh, one more thing, when I run csh as the shell it grumbles about not being
able to access the tty properly (it is running under chat'open_proc)
it complains that oictl is not available.  I'm  not surprised - sort of...
but how do normal telnet-in links manage?

Thanks
--

"And all I wanted was a word, a photograph to keep"
Madness, "Michael Caine"



Sat, 07 Dec 1996 04:33:22 GMT  
 telnet chars and chat regexs
To give the answer to my own problem...



1) Why does /(.|\n)/ match one character, /(.|\n)+/ match them all but
   /(.|\n)*/ not match any, especially as the * is supposed to be greedy?

A) I don't know.

2) Problem with interpretations of \012 and \015 in telnet streams...

The answer is: the bahaviour of \012 and \015 can be controlled in context
(without mucking up escape sequences) using stty

--
*----------*-------------------------------------------------------------*
| Sam   Jam|"Never underestimate the importance of a cheap laugh"-       |

*---For ScoobyDoo episodes mail with "hoi! list scooby" as subject line--*



Sat, 07 Dec 1996 20:03:36 GMT  
 telnet chars and chat regexs

Sam> To give the answer to my own problem...


Sam> 1) Why does /(.|\n)/ match one character, /(.|\n)+/ match them all but
Sam>    /(.|\n)*/ not match any, especially as the * is supposed to be greedy?

Sam> A) I don't know.

Chat'expect requires you to answer the problem:

        *how* will I know when I have *seen enough*?

There are two ways out:  a timeout, or a match.

For a match, you get out as *soon* as the stream has generated text
that matches.  Remember that the text comes in *clumps*, thanks to the
way a TCP connection works.

So, for /.|\n/, you get out as soon as you see one character, but
you've probably seen a lot right then too.  The rest are *ready* to be
read in the internal chat buffer.

For /(.|\n)+/, you *still* have to have at least one character, but
because of the "clumpiness" of the transmission, you'll get everything
that came in the first clump.

For /(.|\n)*/, you can match zero characters!  There are zero
characters available *right away*, so that's the *soonest* it can
return, so you get zero.  (Actually, if you slept a few seconds, you'd
probably get the first clump instead, demonstrating that the star
there really *is* greedy.)

So, crafting an expect string is a black art.  I'd be happy to help
you with it offline.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)

--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Phrase: "Welcome to Portland, Oregon ... home of the California Raisins!"



Sun, 08 Dec 1996 03:40:03 GMT  
 telnet chars and chat regexs
:
: Hi all, 2 questions:
:
: I need a regex to match EVERYTHING.
: The data I am matching to can contain anything even lots of \n's
:
: I have set $*=1;,
:
: I am using it as a regex in the &expect routine of chat2
:
: Currently, all that works is
:
: '(.|\n)' to match one character, because
: '(.|\n)*' does not match ANY
: yet
: '(.|\n)+' does exactly what I want - NOW if * is greedy, what changed its
: mind...

I would suspect that the pattern is applied against the string before the
first read, so that your second pattern can match against a null string.
The others force a read, and then have as much to match against as the
desire on the next iteration.

Larry



Mon, 09 Dec 1996 01:47:52 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Net::Telnet->cmd + > 256 chars

2. Issues with interpolating regexs

3. Index and Regexs

4. maps and regexs

5. Matching many similar regexs

6. RegExs and question marks...a possible bug?

7. Compiling regexs for efficency

8. difference in execution time of regexs

9. @chars the same as ($#chars) ?

10. Replacing special chars with special chars

11. Q: using a c-lib with char** and even char***

12. s/Hex/Char/ ? s/Char/Hex/

 

 
Powered by phpBB® Forum Software