Arexx (67/92)

From:Andrew Bruno
Date:23 Jan 2000 at 00:07:07
Subject:a bit of my code.

From: Andrew Bruno <abruno@zeta.org.au>

Hi,

As most of you would have gathered by now, I am still a bit of a rookie at
codes, but have a bit of an interest.

Presently I am playing with code breaking and am using AREXX to help me find
patterns.

I have posted a couple of my efforts.

Here is another one.

The idea is simple enough.

It looks for repeats. ;)

I have done the best I can, but I don't understand the structure of
functions in AREXX so I have written it very "top to bottom" in style.

It is good and bad at the same time.

Good, as in it is easy to understand, bad, as in it can be better.

Down in the "main" loop, when it has found matches, is my problem. The lp
is the FIRST position the SEARCH string is found, and the i is the
subsequent ones.

What I am wanting is a result file to look something like this:

repeat scan for '|| l ||' length patterns
Found WXIZAY at position/s 106 296
Found XIZAYG at position/s 107 297
Found NUOCZG at position/s 177 257
Found UOCZGM at position/s 178 258

But when it finds MORE than two, it just keeps sticking the next number on
the end.

As it now, this is what happens:

Found IDGM at position/s 350 515
Found IDGM at position/s 350 575

I got around the original problem of no matches being entered, by removing
the initial writeln() outside the loop and waited for the match to happen.

But by then, I had lost the original string and position. That is why I had
to put in the leading text and the "positions/s" bit.

Alas that falls over with the 3'rd (etc) hits.

I could nest it again, but that seems a bit excessive. ;)

Can anyone please show me how to get around it?

(at this stage, please don't have a field day and re-write the whole thing
unless ABS() needed. I am trying to learn.

/* */

/* Please note! The files you are scanning MUST be ONE line ONLY! */

options results

parse arg infile' 'l

if infile = "" then
do
echo 'Syntax:'
echo ' infile - the file to scan.'
echo ' l - length of the search.'
end

lp = 1

call open('x1','d:puzzel4.txt','R')
LongString = readch('x1',630)
call close('x1')

len = length(LongString)

echo 'length of search is '|| l
echo 'Search string length is '|| len

name = 'D:results_'||l
header = 'repeat scan for '|| l ||' length patterns.'
call open('x2',name,'W')
call writeln('x2',header)

echo ' '
echo ' '
echo ' Busy..... Please stand bye!'
echo ' '

do until lp = len-l

search = substr(LongString,lp,l)

counter = 0

do i = (l+lp+1) to len
x = search = substr(LongString,i,l)
if x = 1 then
do
msg1 = 'Found '||search||' at position/s '||lp ||' '|| i
call writeln('x2',msg1)
counter = counter + 1
echo 'hits on '||search||' so far = '||counter+1
end
end
lp = lp + 1
/* echo 'lp = '||lp */
end

call close('x2')

echo ' '
echo ' '
echo ' '
echo ' All done. Results in file: results_'|| l

Thanks again!

Cya!



Lawyer: the larval form of a politician.

Andrew Bruno
abruno@zeta.org.au

--------------------------- ONElist Sponsor ----------------------------

Hey Freelancers: Find your next project through JobSwarm!
You can even make money in your sleep by referring friends.
<a href=" http://clickme.onelist.com/ad/jobswarm1 ">Click Here</a>

------------------------------------------------------------------------

ARexx mailing list - No flames, no overquoting, no crossposting. Unsubscribe: Blank mail to mailto:arexx-unsubscribe@onelist.com