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 is the use of command “use strict”?
What is the different between array and hash in perl programming?
Explain a tell function in perl?
Which has the highest precedence, List or Terms? Explain?
How to add elements in a hash in perl?
How to print escaping characters inside a string in perl?
What is perl scripting?
Define perl scripting?
What does undef function in perl?
We all know private variables exist in perl. But do private METHODS exist in perl ? Eg ?
How to open and read data files with Perl
what are the two ways to get private values inside a subroutine or block?
What is qq (double q)operator in perl?
How do I send e-mail from a Perl/CGI program on a Unix system?
Difference between the variables in which chomp function work ?