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


Please Help Members By Posting Answers For Below Questions

Explain ivalue in perl?

705


How to convert arrays into a string in perl?

670


How the interpreter is used in Perl?

705


How to turn on Perl warnings? Why is that important?

750


How to sort arrays in perl?

801


How to know whether a key exists or not in perl?

719


How do I generate a list of all .html files in a directory?

703


How many ways can we express string in Perl?

709


What does -> symbol indicates in Perl?

746


Which operator in perl is used for the concatenation of two strings?

710


Enlist the advantages of using c over perl?

685


How does a “grep” function perform?

775


How to change a directory in perl?

712


What are the benefits of perl in using it as a web-based application?

658


In Perl, what is grep function used for?

715