Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Perl: How to reference an array in foreach loop?

 
Highlighted
Regular Advisor

Perl: How to reference an array in foreach loop?

Hi!

I have a small problem with my CGI-skript.
I have a foreach loop, which should display anything:

foreach $element (@nameList){
print $element;
print XXXXXX;
}

The problem is exactly where XXXX is: There should be an array, which name is the name contained in $element, for example $element=cpu, then array's name is @cpu.

If I put @$element on that place, I get always the previous output again, for example in the first loop I have @cpu, in the 2 loop I have @tty, and instead getting only the @tty contents, I'm getting again the cpu-contents and after this the tty-content. The same picture with three elements: I get 3 ouputs, instead of one...and so on..
How can I change it, so that this behaviour disappears?

Thank you!
1 REPLY 1
Regular Advisor

Re: Perl: How to reference an array in foreach loop?

Error seems to be somewhere else...