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 |
We all know private variables exist in perl. But do private METHODS exist in perl ? Eg ?
Suppose an array contains @arraycontent=(‘ab’, ‘cd’, ‘ef’, ‘gh’). How to print all the contents of the given array?
How do I debug a perl program?
What purpose does each of the following serve: -w, strict, - T ?
What is a chop() function in perl?
what are the steps involved in reading a cgi script on the server?
Explain regular expression in perl?
Which feature of Perl provides code reusability ? Give any example of that feature.
Write a program to download the contents from www.perlinterview.com/answers.php website in Perl.
what is the meaning of rigging?
How to close a directory in perl?
write a script to generate n prime no.s?