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 cpan ? What are the modules coming under this?
How does polymorphism work in perl? Give an example.
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 '->' in perl?
What are the various file operations in perl. Explain with example.
Explain subroutine in perl?
How to concatenate strings in perl?
How to read a file into a hash array?
Explain perl. When do you use perl for programming?
How to check the status of airplane mode (enable/disable) in perl for Android mobile?
What is the use of now constructor in perl?
What is the easiest way to download the contents of a URL with Perl?
What are the advantages of c over Perl?
what are the two ways to get private values inside a subroutine or block?
Which has highest precedence in between list and terms? Explain?