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

Which of these is a difference between Perl and C++ ?

0 Answers  


how to search a unique pattern in a file by using perl hash map function ??? plz answer me

2 Answers  


What is a chop() function in perl?

0 Answers  


What is the difference between exec and system?

0 Answers  


You want to add two arrays together. How would you do that?

0 Answers  






Write syntax to add two arrays together in perl?

0 Answers  


Explain subroutine?

0 Answers  


Which feature of perl provides code reusability?

0 Answers  


I have one question regarding to eval function. I know eval function is use for error checking but I am not able to understand below line. eval \'exec perl -S $0 ${1+\"$@\"}\' if 0; $0 for script name $@ set if error occur

0 Answers  


What does localtime() do in perl?

0 Answers  


How do you find the length of an array?

0 Answers  


What is 'rollback' command in perl?

0 Answers  


Categories