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

Explain ivalue in perl?

0 Answers  


What are scalar data and scalar variables?

0 Answers  


How many data types are there in perl?

0 Answers  


Write a script to reverse a string without using perl's built in functions?

0 Answers  


what is Polymorphism in Perl?

0 Answers  


What is the difference between module and package?

4 Answers   EDS, IBM, Symantec,


what is perl language?

0 Answers  


Explain goto expr?

0 Answers  


Explain the difference between declarations of 'my' and 'local' variable scope in perl?

0 Answers  


Explain join function in perl?

0 Answers  


Write the program to process a list of numbers.

0 Answers  


How and what are closures implemented in perl?

0 Answers  


Categories