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?
Answers were Sorted based on User's Feedback
Answer / 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 |
Explain tk?
How do you set environment variables in perl?
What does the qx{ } operator do?
What is hash?
Why -w argument is used with perl programs?
What is posix in perl?
what is Chop & Chomp function does?
What does the command "use strict" do and why should you use it?
Give an example of the -i and 0s option usage.
What is the tk module?
What are the features of perl language?
“Perl regular expressions match the longest string possible”. What is the name of this match?