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

How do you debug a Perl scripting ( at the compile time error or run time error) in Unix environment ?

4 Answers  


What are the various uses of perl?

1 Answers  


Define print() function in perl?

1 Answers  


How to copy a file in perl?

1 Answers  


Does Perl have objects? If yes, then does it force you to use objects? If no, then why?

1 Answers  


How does polymorphism work in perl? Give an example.

1 Answers  


write a perl script to find whether a given line of text is starting and ending with same word or not ???

2 Answers   CSS,


Explain perl. When do you use perl for programming? What are the advantages of programming in perl?

1 Answers  


Write an example explaining the use of symbol tables.

1 Answers  


How to get help for perl?

1 Answers  


What is the function of virtual documents in cgi programs?

1 Answers  


What is the different between array and hash in perl programming?

1 Answers  


Categories