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 |
Write a program that shows the distinction between child and parent process?
How to create a package?
What is the use of "stderr()"?
what is the difference between java and cgi?
How will you open a file in a write-only mode in perl?
Where the command line arguments are stored and if you want to read command-line arguments with Perl, how would you do that?
What is the purpose of redo statement?
Which guidelines by Perl modules must be followed?
How do I read command-line arguments with Perl?
what is the difference b/w coldfusion MX 6 and Coldfusion MX 7?
If EXPR is an arbitrary expression, what is the difference between $Foo::{EXPR} and *{"Foo::".EXPR}?
What is the difference between having a parenthesis after module name and without parenthsis after module name?? i.e Package::Module(); and Package::Module;