Page 1 of 1 1
Topic Options
#42851 - 2003-07-15 10:31 PM Searching an array
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
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

Top
#42852 - 2003-07-15 10:33 PM Re: Searching an array
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Borrowing from the manual...
quote:
AScan( )

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


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#42853 - 2003-07-15 10:35 PM Re: Searching an array
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
Perfect...I looked through the manual but I must have missed that....I will give that a shot thanks.
Top
#42854 - 2003-07-15 10:37 PM Re: Searching an array
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
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

_________________________
There are two types of vessels, submarines and targets.

Top
#42855 - 2003-07-15 10:43 PM Re: Searching an array
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#42856 - 2003-07-15 11:29 PM Re: Searching an array
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
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.

Top
#42857 - 2003-07-15 11:36 PM Re: Searching an array
sliver Offline
Getting the hang of it

Registered: 2002-09-05
Posts: 94
Sealeopard...I would use the string replace but some of the queue names are different....that is why I need to match them up.
Top
#42858 - 2003-07-15 11:56 PM Re: Searching an array
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42859 - 2003-07-16 04:24 AM Re: Searching an array
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#42860 - 2003-07-16 04:33 AM Re: Searching an array
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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.
_________________________
!

download KiXnet

Top
#42861 - 2003-07-16 04:41 AM Re: Searching an array
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Or even better a .INI file
code:
[Printer Migration]
\\oldprinter\oldshare=\\newprinter\newshare

_________________________
There are two types of vessels, submarines and targets.

Top
#42862 - 2003-07-16 04:47 AM Re: Searching an array
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Don't you guys like my HASH [Confused] [Frown]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42863 - 2003-07-16 05:00 AM Re: Searching an array
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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]
_________________________
!

download KiXnet

Top
#42864 - 2003-07-16 07:53 PM Re: Searching an array
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
What about this one

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

_________________________
Eric

Top
#42865 - 2003-07-16 07:58 PM Re: Searching an array
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
whoa ... a JoinSplit with a half Split !!! [Eek!]

The Canadian judge gives that a 10.

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

Top
#42866 - 2003-07-16 08:05 PM Re: Searching an array
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Thanks Shawn. I had to do a lot of stretching before I attempted all those splits [Wink]
_________________________
Eric

Top
#42867 - 2003-07-16 10:11 PM Re: Searching an array
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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.
_________________________
!

download KiXnet

Top
#42868 - 2003-07-16 11:36 PM Re: Searching an array
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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 !

Top
#42869 - 2003-07-16 11:47 PM Re: Searching an array
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
I said ultimate [Big Grin]
as far as I remember, he has only participated in 2 of them [Wink]
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 104 anonymous users online.
Newest Members
vertage, dimi575, Drecksnacken, Nlill, webtools321
17735 Registered Users

Generated in 0.043 seconds in which 0.012 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org