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?
Answer Posted / 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 View All Answers
What does init 5 and init 0 do?
You want to read command-line arguements with perl. How would you do that?
Explain lists in perl?
Define say() function in perl?
Why should I use the -w argument with my Perl programs?
Explain chomp, chop, cpan, tk.
What are perl variables?
How can memory be managed in Perl?
Which of these is a difference between Perl and C++ ?
How do you find the length of an array?
Who created perl?
Write a cgi program to show the header part?
what are the two ways to get private values inside a subroutine or block?
Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.
How to get help for perl?