Using RegEx to search text file and create variable array

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Sun Jun 10, 2007 3:38 pm

After some testing, i'm finding that for some reason the code reliably skips the first URL in each file.

Eg. if there are 4 urls, it will skip the first URL and read the last three. If there are 5 urls, it will read the last four. If there is only one URL it will not bring back any urls.

Any ideas?

Aaron wrote:
what if i want it to loop as much as 5 times
If you had 100 url it would find them all.

Hope this helps

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

array will start at 0

Post by Aaron » Mon Jun 11, 2007 3:41 am

I saw at the outset that you where being led astray.

The array will start at 0 being the first url.

I did not say anything because you had some sharp individuals helping you and I was'nt sure how to start.

Here is what you were told
If>URLS_COUNT>0
Let>k=1
Repeat>k
Let>ThisURL=URLS_%k%
MessageModal>ThisURL
//we could write it to a file:
WriteLn>outputfile,result,ThisURL
Let>k=k+1
Until>k=URLS_COUNT
Endif
Here is what I think will work?

Code: Select all

If>URLS_COUNT>0
  Let>k=0
  Repeat>k
    Let>ThisURL=URLS_%k%
    MessageModal>ThisURL
	//we could write it to a file:
	WriteLn>outputfile,result,ThisURL
    Let>k=k+1
  Until>k=URLS_COUNT
Endif

Like I said, I'm not sure how to start this, If there is only 1 url, URLS_COUNT will be equal to 0 not graeter than 0.

The problem I believe has been that it is skipping the url in the array[0] spot.

I would wait for a response from Marcus on this post as I have been using MS for only 2 months, but im pretty sure im correct on this

Good luck
Aaron

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jun 11, 2007 5:03 am

clickfast,
Could you post your non-functional code so we can take a look at it.

Aaron,
Sorry but the Separate> command creates a list of variables starting with "VariableName_1" not "VariableName_0". See help for Separate>.

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Thu Jun 14, 2007 4:19 am

JRL wrote:clickfast,
Could you post your non-functional code so we can take a look at it.
Preceding this code reads an xml file and use the separate function to put a list of urls into a variable.

Then the following script reads the variables and writes them to a text file. However, the script reliably skips the first url in the variable list above. Eg. if there are two urls it skips the first and writes the 2nd one to text, etc. It always skips the first URL)

Code: Select all

If>URLS_COUNT>0
  Let>k=1
  Repeat>k
    Let>k=k+1
	Let>ThisURL=URLS_%k%
	//write it to a file:
	WriteLn>D:\BandLauncher\Activeperlscripts\BANDS\%band%-%id%\BandGenerator\urls.txt,result,ThisURL
  Until>k=URLS_COUNT
Endif
Last edited by clickfast on Sat Jun 16, 2007 12:10 am, edited 1 time in total.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Jun 14, 2007 3:20 pm

Untested, but

Change from Let>k=1
Change to: Let>k=0
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Thu Jun 14, 2007 7:24 pm

Hey Bob, so I tried Let>K=0 and it literally returned "URL_COUNT=0" as the first url and the rest of the URLs were retrieved as usual??

This is a weird one. And I really appreciate everyones help!!
Bob Hansen wrote:Untested, but

Change from Let>k=1
Change to: Let>k=0

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Jun 14, 2007 9:04 pm

I tried Let>K=0
What if you try:
Let>k=0
as originally posted?

K k
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Thu Jun 14, 2007 9:40 pm

that is what i used originally. And it causes the script to skip the first url in the list.
Bob Hansen wrote:
I tried Let>K=0
What if you try:
Let>k=0
as originally posted?

K k

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Jun 14, 2007 10:14 pm

Have you done:

MDl>URLList

(if that's still the pre-separate variable name) and verified that all the URL's are actually in there?
Last edited by Me_again on Thu Jun 14, 2007 10:15 pm, edited 1 time in total.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Jun 14, 2007 10:14 pm

Duh, meant to edit not quote...

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Jun 14, 2007 10:51 pm

I think when you first used
Let>k=0
you had your Let>k=k+1 at bottom of the script vs. having it at the top like the most recent example you provided. It makes a big difference.

When at the top, the first value will be =1
When at the bottom, the first value will be 0

When at the top, your last processing will be the last line.
When at the bottom, you will not do the last line because total will be increased firts.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Sat Jun 16, 2007 12:18 am

Yes Me_again... did the MDI>URLList and all the URL's are actually there. So it is definitely something post SEPARATE... which is what this thread is focused on at this point.
Me_again wrote:Have you done:

MDl>URLList

(if that's still the pre-separate variable name) and verified that all the URL's are actually in there?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Jun 16, 2007 12:46 am

This works pefectly:

Let>URLList=http://www.yahoo.com;http://www.google.com;http://www.mjtnet.com;http://www.microsoft.com;http://www.ebay.com
Separate>URLList,;,myurls
If>myurls_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
MDL>myurls_%k%
Until>k,myurls_count
Label>end

so there's nothing wrong with the code that has been suggested.

I think you need to look very carefully at what you are actually getting in URLList, maybe there are control characters in there, or additional delimiters, maybe try a different delimiter like the "|" pipe symbol.

clickfast
Pro Scripter
Posts: 58
Joined: Wed May 23, 2007 12:04 am

Post by clickfast » Sat Jun 16, 2007 6:35 am

FIXED!!! HERE'S WHAT IT LOOKS LIKE.. THE PROBLEM APPEARED TO BE THE UNTIL LINE:

Code: Select all

UNTIL>k=URLS_COUNT
USING A PORTION OF ME_AGAIN'S CODE ABOVE I REPLACED THE [=] FROM THE PREVIOUS SUGGESTIONS IN THIS THREAD WITH A [,] AND NOW THE UNTIL LINE LOOKS LIKE THIS

Code: Select all

UNTIL>k,URLS_COUNT
AND IT WORKS NOW AND CAPTURES ALL URLS CORRECTLY!!!

HERE'S THE FINAL CODE:

Code: Select all

IF>URLS_COUNT>0
LET>k=0
Repeat>k
Let>k=k+1
Let>ThisURL=URLS_%k%
//write it to file
WriteLn>C:\urllist.txt
Until>k,URLS_COUNT
Endif
THANKS ALL!!! [/b][/quote]

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Jun 16, 2007 1:40 pm

Good catch :D

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts