Re: array question



On Tue, Feb 26, 2008 at 8:07 AM, <Irfan.Sayed@xxxxxxxxxxxxx> wrote:
Hello All,



I have two arrays contains exact no. of elements. Now what I need to do
is , I want to execute certain commands to each elements of the array at
a time.



It means that I want take first element of first array and first element
of second array and then want to execute certain commands considering
these two elements.

I don't know how should I achieve this in perl.



Please help.



Regards

Irfan.







A simple for statement should do it;

my @array1= qw/1 2 3 4/;
my @array2= qw/1 2 3 4/;
for 0..$#array1 {
#your code here..
print $array1[$_] + $array2[$_],"\n";
}
.



Relevant Pages

  • Re: foreach - sorted array the way I want?
    ... It pushes each command to an array. ... such approach does not guarantee that the commands will be ... And then, simply execute commands from @execute_first, ... You might consider sorting the @exec_commands array, ...
    (comp.lang.perl.misc)
  • Re: Reading Files Byte-For-Byte
    ... >> attempting to read the file into an array. ... to be slower due simply to the additional commands required to accomplish ... I think the misunderstanding came about due to your mentioning reading the ... of printable characters, you'll need to do something else if your file data falls ...
    (microsoft.public.vb.general.discussion)
  • Re: Array assignment
    ... > When I do that sort of thing in C, I declare an array that sizes itself ... > to however many commands there are this week. ... const); forward; ...
    (comp.lang.pascal.delphi.misc)
  • array question
    ... I want to execute certain commands to each elements of the array at ... It means that I want take first element of first array and first element ...
    (perl.beginners)
  • foreach - sorted array the way I want?
    ... I have a script which reads the config file and builds the commands which need to be executed. ... It pushes each command to an array. ... such approach does not guarantee that the commands will be executed in a proper order. ... And then, simply execute commands from @execute_first, @execute_second, and so on? ...
    (comp.lang.perl.misc)