my @array=('data1','data2'); my @array1=('data1','data2');
my ($i,$k);
$i=7;
$k=7;

while($i){
$array [++$#array] = 'ree';
$i--; print "@array";
}

while($k){
push(@array1,'ree');
$k--;
print "@array1";
}


Are these two while loop are doing the same functionality ?
What may be the difference?



my @array=('data1','data2'); my @array1=('data1','data2'); ..

Answer / guest

The above two while loops are used to add the elements into
the end of the array.
But in first while loop we are manually getting the index of
the last element in the array then we are storing the
element into next index.

But push internally performing that operation.
And the push() has some advantages also.

Using push we can add multiple items into an array in a
single instance.
But this is not possible in the fist while loop.

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More CGI Perl Interview Questions

How to make the following assignment, as arrayreference assignment ? my $arr_ref='[1,2,3,4,4,'elem']';

2 Answers  


How to do comment in perl?

0 Answers  


What are some common methods to all handles in perl?

0 Answers  


What is perl pop array function?

0 Answers  


Explain returning values from subroutines?

0 Answers  






Write a program to show the process of spawning a child process

0 Answers  


How do you find the length of an array?

0 Answers  


Mention the difference between die and exit in Perl?

0 Answers  


What are the advantages of programming in perl?

0 Answers  


Explain grooving and shortening of arrays?

0 Answers  


How many types of primary data structures in Perl and what do they mean?

0 Answers  


Define dynamic scoping.

0 Answers  


Categories