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
Why is it hard to call this function: sub y { "because" } ?
We all know private variables exist in perl. But do private METHODS exist in perl ? Eg ?
How can you use Perl warnings and what is the importance to use them?
you are required to replace a char in a string and store the number of replacements. How would you do that?
Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.
What is the different between array and hash in perl programming?
Perl uses single or double quotes to surround a zero or more characters. Are the single(' ') or double quotes (" ") identical?
Differentiate between arrays and list in perl.
Explain subroutine in perl?
Explain tk?
How to renaming a file in perl programming?
Explain USE and REQUIREMENT statements?
What $! In perl?
how to get back up from private character editor which is saved in the format of .udf
How do I replace every character in a file with a comma?