sliver
(Getting the hang of it)
2003-07-15 10:31 PM
Searching an array

I have an array called $oldprintarray and an array called $newprintarray.

In each array is a printer mapping like so.

$oldprintarray:

$oldprinter1=\\server\path1
$oldprinter2=\\server\path2
$oldprinter3=\\server\path3

$newprintarray:

$newprinter1=\\server\path1
$newprinter2=\\server\path2
$newprinter3=\\server\path3

OldPrinter1 represents the printer to be replaced and NewPrinter1 represents the replacement.

I have to do it this way because the servers and the queue names are not the same.

The arrays are pulled from 2 seperate text files that the NT Server team will be populating.

In my script if $OldPrinter1 is detected on the system then I want it to be replaced with $NewPrinter1. $OldPrinter1 will always go with $NewPrinter1 and $OldPrinter2 will always go with $NewPrinter2 etc.

Is there a way to search $newprintarray for the corresponding printer without using a "For Each"

Ex.-

I already know new $oldprinter1 is on my machine and needs to be replaced. Now I want to replace it with it's cooresponding value ($newprinter1).

How can I match this??

Sorry if this is a little confusing.

Thanks,
S


Les
(KiX Master)
2003-07-15 10:33 PM
Re: Searching an array

Borrowing from the manual...
quote:
AScan( )

Action: Searches an array for an element containing the same value as an expression.




sliver
(Getting the hang of it)
2003-07-15 10:35 PM
Re: Searching an array

Perfect...I looked through the manual but I must have missed that....I will give that a shot thanks.

Sealeopard
(KiX Master)
2003-07-15 10:37 PM
Re: Searching an array

Use ASCAN to find an array element or do a simple string replace like
code:
$a='\\server1\printer'
$a=replace($a,'server1','server2')
function replace($string,$search,$replace)
$replace=join(split($string,$search),$replace)
endfunction



Kdyer
(KiX Supporter)
2003-07-15 10:43 PM
Re: Searching an array

These will probably help you as we recently completed a printer migration from one server to another -

Prevent special printers from being deleted

Here is a synopsis of what we went through -
Printer Migration

HTH,

Kent


sliver
(Getting the hang of it)
2003-07-15 11:29 PM
Re: Searching an array

Can you search for a substring with ASCAN....ie....

I just want to find the text NEWPRINTER1....If that text is in any of the elements we have a match. I have been messing with it but I have not been able to successfully get this to work.

KDYER....thanks...I will look through this code tomorrow.


sliver
(Getting the hang of it)
2003-07-15 11:36 PM
Re: Searching an array

Sealeopard...I would use the string replace but some of the queue names are different....that is why I need to match them up.

Howard Bullock
(KiX Supporter)
2003-07-15 11:56 PM
Re: Searching an array

I think that the optimum method to associate your two arrays is to use my HASH library which you can find in the UDF library and on Jooel's (Lonkero's) UDF mirror site.

The example in the UDF script will demonstrate how to use it. I think you will see an immediate correlation to your your implementation needs.


Sealeopard
(KiX Master)
2003-07-16 04:24 AM
Re: Searching an array

Still, you can use the replace function I posted above in combination with a FOR-EACH. Please study the examples given to you as the REPLACE will fit your bill.

LonkeroAdministrator
(KiX Master Guru)
2003-07-16 04:33 AM
Re: Searching an array

I think you would be better of with one file.
it having:
"\\oldserver\oldprinter"="\\newserver\shoeprinter"

kinda...
this way the match is already done for each.


Sealeopard
(KiX Master)
2003-07-16 04:41 AM
Re: Searching an array

Or even better a .INI file
code:
[Printer Migration]
\\oldprinter\oldshare=\\newprinter\newshare



Howard Bullock
(KiX Supporter)
2003-07-16 04:47 AM
Re: Searching an array

Don't you guys like my HASH [Confused] [Frown]

LonkeroAdministrator
(KiX Master Guru)
2003-07-16 05:00 AM
Re: Searching an array

lol.
the word hash (just like regexpr) sound so unix to me [Wink]

we just might not dear to use your UDFs... who knows, they might be too powerfull [Wink]


maciep
(Korg Regular)
2003-07-16 07:53 PM
Re: Searching an array

What about this one

code:
split(split(join($newprintarray, ";"), "newprinter1=")[1], ";")[0]



ShawnAdministrator
(KiX Supporter)
2003-07-16 07:58 PM
Re: Searching an array

whoa ... a JoinSplit with a half Split !!! [Eek!]

The Canadian judge gives that a 10.

[ 16. July 2003, 19:59: Message edited by: Shawn ]


maciep
(Korg Regular)
2003-07-16 08:05 PM
Re: Searching an array

Thanks Shawn. I had to do a lot of stretching before I attempted all those splits [Wink]

LonkeroAdministrator
(KiX Master Guru)
2003-07-16 10:11 PM
Re: Searching an array

half split?
shawn, to me it looks full.

maciep, I'm glad to see someone else uses these powerfull kixtart shortcuts than the ultimate kixgolf hardknocks.


ShawnAdministrator
(KiX Supporter)
2003-07-16 11:36 PM
Re: Searching an array

Yes, I stand corrected. But the term half-split just sounded better [Wink]

In terms of golf ... i thought maciep was a hard-knock KiXgolfer ?! I recognised the coding style as soon as I saw it. A style forged in the heat of battle, wrought by a scripter skilled in the black-arts of KiXgolf ... its very obvious !


LonkeroAdministrator
(KiX Master Guru)
2003-07-16 11:47 PM
Re: Searching an array

I said ultimate [Big Grin]
as far as I remember, he has only participated in 2 of them [Wink]