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



my @array=('data1','data2'); my @array1=('data1','data2'); ..

Answer / neo

Both are same

Is This Answer Correct ?    2 Yes 1 No

my @array=('data1','data2'); my @array1=('data1','data2'); ..

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

Post New Answer

More CGI Perl Interview Questions

What are the steps involved in configuring a server using cgi programming?

0 Answers  


What is 'rollback' command in perl?

0 Answers  


What are the various uses of perl?

0 Answers  


how to install a package in perl ????

2 Answers  


What is confess function in perl?

0 Answers  






Why we use "use lib $path"?

1 Answers  


How to close a directory in perl?

0 Answers  


How can you create an object of a class in a package?

4 Answers   IBM,


Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.

0 Answers  


Explain what is STDIN, STDOUT and STDERR?

0 Answers  


What is the difference between exec and system?

0 Answers  


What are the options that can be used to avoid logic errors in perl?

0 Answers  


Categories