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 cgi program store?
Define say() function in perl?
Write a program to decode the data in the form using cgi programming
What is chomp() operator/function?
How to determine strings length in perl?
What is perl I used for?
Suppose an array contains @arraycontent=(‘ab’, ‘cd’, ‘ef’, ‘gh’). How to print all the contents of the given array?
You want to concatenate strings with perl. How would you do that?
What is the purpose of goto expr statement?
What is the use of strict?
What does undef function in perl?
How are parameters passed to subroutines in perl?
What is the difference between perl array and perl hash?
“Perl regular expressions match the longest string possible”. What is the name of this match?
How do I sort a hash by the hash value?