several Qs 
Author Message
 several Qs

I have a few awk questions:

1)Can/How do you use varibles in regular exp?
ie I have code that looks like:
if  ($i=="/[\220-\252\310-\355\357-\370A-Z]+\371[\220-\252\310-\355\357-\370A-Z]+[\,\;]/")
as you can see its pretty messy with a lot of repititions

2)Is line of code correct: $i="{orth}" $i "{\/orth}"
I don't get any errors from nawk but when I try to use a2p (this is a function that converts awk to perl. I know awk but I need the power of Perl ie no limit to number of records) I get a syntax error and since my code isn't working properly anyway I'm assuming that tthe translator is better at catching errors.

3)Is there an easy way to translate lex to awk?

4)Are there EUCs I should watch out for? ie in my above code with all the octal ranges could there be a character with a special meaning in awk?

Thanks a lot.
---Alex



Fri, 08 Jan 1999 03:00:00 GMT  
 several Qs


Quote:

>I have a few awk questions:

>1)Can/How do you use varibles in regular exp?
>ie I have code that looks like:
>if($i=="/[\220-\252\310-\355\357-\370A-Z]+\371[\220-\252\310-\355\357-\370A-Z]+[\,\;]/")

Are you sure you should be using == there instead of ~ ?
You might be able to build a string using something like:
x220="\220-\252\310-\355\357-\370"
myexpr="/[" x220 "A-Z]+\371" x220 "A-Z]+[\,\;]/"
if ($i~myexpr)
Quote:
>as you can see its pretty messy with a lot of repititions

>2)Is line of code correct: $i="{orth}" $i "{\/orth}"

It looks okay to me.

Quote:
>4)Are there EUCs I should watch out for? ie in my above code with all

the octal ranges could there be a character with a special meaning in awk?
As far as I know, no non-ASCII character (characters greater than \177)
has any special meaning in awk.

--

"Outside of a dog, a book is man's best friend.  Inside a dog, it's too
dark to read." -- Marx



Sat, 09 Jan 1999 03:00:00 GMT  
 several Qs

: I have a few awk questions:

: 1)Can/How do you use varibles in regular exp?
: ie I have code that looks like:
: if  ($i=="/[\220-\252\310-\355\357-\370A-Z]+\371[\220-\252\310-\355\357-\370A-Z]+[\,\;]/")
: as you can see its pretty messy with a lot of repititions

First of all, that's not a regexp match, it's an equality. You wish
$i~/.../
... and yes, you may assign the longish R.E. above to a variable, and use:
$i~longre

: 2)Is line of code correct: $i="{orth}" $i "{\/orth}"

It is certainly syntactically correct, but I believe you wish
$i="{orth}" $i "{\\/orth}"
to properly insert a literal backslash inside the double-quoted string.

: I don't get any errors from nawk but when I try to use a2p (this is a function that converts awk to perl. I know awk but I need the power of Perl ie no limit to number of records) I get a syntax error and since my code isn't working properly anyway I'm assuming that tthe translator is better at catching errors.

I have _never_ been able to just use a2p without needing to do some minor
manual readjustments to the created code. (But then again I've always been
a hard-luck programmer. :-)

: 3)Is there an easy way to translate lex to awk?

Since lex implements an extended form of R.E.s incorporating R.E.
inclusion with {..}s, read-ahead ("/"), and the notion of "states",
there is no other solution than to hand-code it. To my knowledge, there
is no software tool to do this automagically.

: 4)Are there EUCs I should watch out for? ie in my above code with all the octal ranges could there be a character with a special meaning in awk?

When specifying an octal range, which is an _undocumented_ feature
appearing in _some_ versions of n/awk, one is then never typing a character
having a special meaning to a regular expression, so what is your question?

The only unresolved mystery yet to be solved in my n/awk programming
experience is to know why the equals sign ("=") in regexps has to be
escaped in SunOS versions of n/awk. This is entirely undocumented
behavior!

: Thanks a lot.

Hoaky doaky.

: ---Alex

-Brian
--
   ,---.     ,---.     ,---.     ,---.     ,---.     ,---.     ,---.  
  /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \  

__,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.__



Fri, 15 Jan 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Input from several fields in several files

2. Qs on CLUBMGR, Template BUG ???

3. Qs

4. Qs about language nomenclature

5. New newbies Qs on Ruby

6. Newbie Qs: startup time, Module.constants, chdir, Ruby distro's library

7. Qs on Ruby and DbC/Smalltalk

8. 2 Qs: IndexedFaceSets & browsers

9. Qs re 'Write & 'Read

10. newbie obj files Qs

11. NASM Qs

12. Newbie Pmode Qs

 

 
Powered by phpBB® Forum Software