Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-dimension Array conventions

Status
Not open for further replies.

KentCK

MIS
Mar 11, 2003
4
US
I have an AWK script that I'm working on and, unfortunately, I don't know AWK at all. I know PERL better so I am trying to convert the AWK script to PERL using the a2p.exe included with the ActiveState perl install.

Anyway.....

The a2p.exe bombs out on several lines. The first one is:

COUNT["security"][$4]++ # used for summary report

I believe this is a multi-dimension (associative) array that would be better written as:

COUNT["security",$4]++ # used for summary report

Once I fix that issue I then get an error on the following line:

VPNSESSION[$4][PORT]["startim"] = time(YEAR,MONTH,DAY,HOUR,MINUTE,SECOND)

Here, I'm stumped. What in the world is it? Multi-multi-dimensional array? The above line is the first time that the array VPNSESSION appears.

Any help I can get on this is greatly appreciated. Please let me know if there is any other information you need. Thanks!!!

Kent
 
this is a multi-dimentional array - you're right.
Try:

VPNSESSION[$4,PORT,"startim"] = time(YEAR,MONTH,DAY,HOUR,MINUTE,SECOND)

I assume 'time' is either a user awk function OR maybe a gawk provided function - not sure of that!

You 'VPNSESSION' is indexed in THREE dimensions - if you're going to write a loop with the 'for iter in VPNSESSION' your 'iterator' [iter] will be will be an array with three cells separated with the value of SUBSEP. You can use 'split(iter, idxARR, SUBSEP)' and reference any of the three dimensions as:
dim1=idxARR[1]
dim2=idxARR[2]
dim3=idxARR[3] vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
So then:

if ($4 in VPNSESSION)
if (PORT in VPNSESSION[$4])
if (&quot;startim&quot; in VPNSESSION[$4][PORT])
SESSTIME = time(YEAR,MONTH,DAY,HOUR,MINUTE,SECOND) - VPNSESSION[$4][PORT][&quot;startim&quot;]


should read:

if ($4 in VPNSESSION)
if (PORT in VPNSESSION[$4])
if (&quot;startim&quot; in VPNSESSION[$4,PORT])
SESSTIME = time(YEAR,MONTH,DAY,HOUR,MINUTE,SECOND) - VPNSESSION[$4,PORT,&quot;startim&quot;]


Is this correct? When I make that change I get an error with the line:

if (PORT in VPNSESSION[$4])

Perhaps the dimension referencing you were refering to has something to do with this?

P.S. Is the myArr[x][y][z]=abc notation just an old way of doing myArr[x,y,z]=abc? Same thing but updated in the case of the latter?
 
Department of Redundancy Department on that P.S., eh?
 

if ($4 in VPNSESSION)
if (PORT in VPNSESSION[$4])
if (&quot;startim&quot; in VPNSESSION[$4][PORT])
SESSTIME = time(YEAR,MONTH,DAY,HOUR,MINUTE,SECOND) - VPNSESSION[$4][PORT][&quot;startim&quot;]

should be

idx=$4 SUBSEP PORT SUBSEP &quot;startim&quot;
if (idx in VPNSESSION)
SESSTIME = time(YEAR,MONTH,DAY,HOUR,MINUTE,SECOND) - VPNSESSION[$4,PORT,&quot;startim&quot;] vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
or better yet:

idx=$4 SUBSEP PORT SUBSEP &quot;startim&quot;
if (idx in VPNSESSION)
SESSTIME = time(YEAR,MONTH,DAY,HOUR,MINUTE,SECOND) - VPNSESSION[idx] vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Oh Gawd! I'm starting to understand this. When will the inhumanity of it all end?!?!?!?

Next in our list of errors (done soon I hope. Line 526 of 630):

delete(VPNSESSION[$4][PORT])

Which I of course changed to:

delete(VPNSESSION[$4,PORT])

But it still doesn't work. Are we trying to delete one of the sub-arrays of the VPNSESSION array or just one subset of elements?

Again, many thanks.
 
your 'VPNSESSION' is a THREE dimensional array - you can't delete a cell referenced by TWO dimensions. You have to specify ALL three dimension indecies:

delete(VPNSESSION[$4,PORT, &quot;startim&quot;]) vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top