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 / sugumar
Both are absolutely same in giving the output.
but in first method "$array [++$#array] = 'ree';"
we are preincrementing the array index manually and assigning the latest index to 'ree'; (SLower since we doing it as manual)
Where as in the second method, push is an array function where we need not care about index. it automatically increases the index value for the array. (Faster)
Both give same output as
data1 data2 ree
data1 data2 ree ree
data1 data2 ree ree ree
data1 data2 ree ree ree ree
data1 data2 ree ree ree ree ree
data1 data2 ree ree ree ree ree ree
data1 data2 ree ree ree ree ree ree ree
VALUES FOR K
data1 data2 ree
data1 data2 ree ree
data1 data2 ree ree ree
data1 data2 ree ree ree ree
data1 data2 ree ree ree ree ree
data1 data2 ree ree ree ree ree ree
data1 data2 ree ree ree ree ree ree ree
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
How to close a directory in perl?
What are perl strings?
Explain the meaning of subroutine?
How to access parameters passed to a subroutine in perl?
How we can navigate the xml documents?
What are the various uses of perl?
What does redo statement do in perl?
What are perl array functions?
How the interpreter is used in Perl?
Why -w argument is used with perl programs?
what is the difference between java and cgi?
How to open a directory in perl?
Write a program to download the contents from www.perlinterview.com/answers.php website in Perl.
What is automatic error handling in perl?
What is perl I used for?