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
What is the use of now constructor in perl?
How to find the length of an array in perl?
Explain ivalue in perl?
What are the steps involved in configuring a server using cgi programming?
Explain chomp?
Perl regular expressions are greedy" what does this mean?
What is the use of 'ne' operator?
How interpreter is used in perl?
Why do we use "use strict" in perl?
What does -> symbol indicates in Perl?
Explain lexical variables.
There is no strict data types in perl unlike in other high level languages like Java so wouldn't that be a problem if a code in perl is to be a written by a big team of 20+ members ?"
Explain chop?
Can inheritance be used in perl? Explain with the help of an example.
What are the arguements we normally use for perl interpreter?