cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Some array issues

pzorrilla
1-Newbie

Some array issues

Hello everybody!!

I'm having a problem with my implementation using Arbortext, I'm working
with ACL and I'm using arrays, and I'm getting an error which I don't
understand and I thought that maybe you could help me in order to
comprehend what it's about this error.

The message that I receive is: A11477 Missing subscript for array variable.

Please if any of you know what's the problem, I would really appreciate
your time and support. Regards.

Paulette Zorrilla
9 REPLIES 9

Sorry! I think this subscription stuff is because I'm not specifying the size, mmmmm... Any of you know about using pointers? I haven't found information of pointer's implementation using ACL. Please I really appreciate your time and support.



Also I would like to knoe if there's someones who could help me with the use of NULL in order to identify a null array for example. 😃 Thanks you so much!!!



Paulette Zorrilla

ACL arrays are very simple (and therefore confusing if you're used to more
powerful, complex array manipulation).

Create an array:
local myarr[]

Fill the first position in an array:
myarr[1] = $foo

Fill a specific position in an associative array:
myarr["Friday"] = $bar

This fails (and, I assume, throws the error you're reporting):
myarr[] = $bang

I think I've got that right.

If this doesn't clear it up, please post your code so we can be sure we're
understanding what you're trying to do that ACL doesn't like.

P.S. It was completely unconscious to set Friday = bar. But you know what
I'm thinking about, right?



On Thu, May 30, 2013 at 2:46 PM, Paulette Zorrilla <
paulette.zorrilla@oracle.com> wrote:

> Sorry! I think this subscription stuff is because I'm not specifying the
> size, mmmmm... Any of you know about using pointers? I haven't found
> information of pointer's implementation using ACL. Please I really
> appreciate your time and support.
>
>
>
> Also I would like to knoe if there's someones who could help me with the
> use of NULL in order to identify a null array for example. 😃 Thanks you so
> much!!!
>
>
>
> Paulette Zorrilla
>
SirkoRudolph
5-Regular Member
(To:pzorrilla)

Hi Paulette,

another pitfall to look for is the index range. If you are used to Java arrays which start from index [0] this is a common error to make with ACL arrays, which start from index [1]. So for example the logic in a for loop is slightly different in ACL, starting the counter from one and comparing for "<=" the size of the array. Not to speak about the possibility to define your own index range for an array, like
global arr[-5..5]

There is a pretty complete explanation about the various array options in the Arbortext Helpcenter (help 194).

Hope that helps.

Kind regards

Sirko Rudolph

Hi Paulette--

A few more tidbits:


1) To check whether an array has any members, you can use the count() function, e.g.
if (count($myarray)==0) {
response("The array is empty");
}
else {
# do something useful
}


2) An easy way to iterate over the elements of an array is using the for...in structure:

for (i in $myarray) {

response("The " . i . "th item is " . $myarray[i]);

}
This works for both indexed arrays and associative arrays.


3) Another potential gotcha: arrays are never returned as return values for functions. If you want a function that fills an array, you have to pass the array in as a parameter. So, you can't do something like this:

function getTitles() {

local titles[];

local n = 1;

local oid = oid_first();

while (oid_valid(oid)) {

if (oid_name(oid)=="title") {

titles[n] = oid;

n++;

}

oid = oid_next(oid);

}

return titles;

}

ACL doesn't know how to return an array. But if you pass in an array as a parameter, the function can modify it so the caller can then do something with it, like so:


function getTitles(titles[]) {

# clear any existing results first

delete(titles);

local n = 1;

local oid = oid_first();

while (oid_valid(oid)) {

if (oid_name(oid)=="title") {

titles[n] = oid;

n++;

}

oid = oid_next(oid);

}

return count(titles);
}

That's a pretty common pattern in the built-in functions, particularly the part where the function fills an array with information and then returns the number of items it put into the array.

Hope that helps!

--Clay

PS There is some pointer support in ACL, but in over 10 years of ACL development I have almost never needed to use them. The one place where they come in handy is passing function pointers so that a function can call another arbitrary function determined at run time. Otherwise, if you are trying to use pointers in ACL, you probably need to rethink your approach to the problem. There is almost always a simpler way to do it.

Hi Paul and everybody!



I'm pretty grateful for your help, and I really appreciate all your comments and suggestions.



Ok, so my suscription error it doesn't appear anymore, but I'm still don't know how to solve my issue, let me explain you more detailed:



I created a global array which I defined as....


size = oid_find_children($srcOid,oids_array,$section);



currentArray[] = oids_array;



for(k=1;k<$size;k++){


currentArray[$k]=oids_arrary[$k];


But I think that I can not get the values inside oids_array[] this way. =( I was thinking about references related with array, so I thought that maybe I need some kind of tool which lets me go inside the memory address of the array.

Hi Paulette--

The easiest way to get what you want is to pass your array directly to the oid_find_children() function:

size = oid_find_children($srcOid, current_array,$section);

The results of the find will be stored in the array, and you can iterate over them and do whatever you like with them.

If you do need a separate copy of the array for some reason, your loop approach should work, except for a couple of things:


1) You misspelled oid_array in your loop. Not sure if that's just a typo in your email or if that was the actual code, but if it's the latter, that would explain why it didn't work for you.

2) Because arrays are indexed from 1, you need to be careful to avoid an off-by-one error at both ends of the range; so your for loop needs to go from 1 up to *and including* k, so you need <= instead of < in your limit test:



for(k=1; k<=$size; k++){

currentArray[$k]=oids_array[$k];

}

--Clay

I would expect

for(k=1;k<$size;k++){

currentArray[$k]=oids_arrary[$k];

}

To work except that you will need to change the k comparison to k<=$size
since the ACL array index starts at 1 not 0. (If you're at all near my age
you will need to touch your nose to the screen to see the difference ... it
is a LESSTHANOREQUALTO comparison.)

What fails in that scenario?



On Fri, May 31, 2013 at 11:01 AM, Paulette Zorrilla <
paulette.zorrilla@oracle.com> wrote:

> Hi Paul and everybody!
>
>
>
> I'm pretty grateful for your help, and I really appreciate all your
> comments and suggestions.
>
>
>
> Ok, so my suscription error it doesn't appear anymore, but I'm still don't
> know how to solve my issue, let me explain you more detailed:
>
>
>
> I created a global array which I defined as....
>
> global currentArray[];
>
>
>
> This global array would maintatin some oids according to a section filter
> which is defined later and used in the next line:
>
> size = oid_find_children($srcOid,oids_array,$section);
>
>
>
> The idea is that the currentArray[] stores the data from oids_array and
> allows me to do some stuff later according to some user's events. I thought
> that only with the next line, the assignment would be made, but here's
> where I got the subscription error.
>
> currentArray[] = oids_array;
>
>
>
> I also tried with a for loop:
>
>
>
> for(k=1;k<$size;k++){
>
> currentArray[$k]=oids_arrary[$k];
>
> }
>
>
>
> But I think that I can not get the values inside oids_array[] this way. =(
> I was thinking about references related with array, so I thought that maybe
> I need some kind of tool which lets me go inside the memory address of the
> array.
>

Onesimple recommendation:If you're trying to learn/research ACL or other topics from a 6.0 Help Center setup, don't.


I keep a copy of a 5.3 Help.chm file where things are more or less organized by topic rather than the hopelessly flat and uncategorized 6.0's.


Kind ofironic for anproduct like Arbortext.

We moved from 5.2 to 6.0 and I noticed that the 6.0 help is definitely less intuitive than the 5.2 help was.
Top Tags