vennirajan has asked for the wisdom of the Perl Monks concerning the following question:
I have written a piece of code to print the file contents. Here is the code,
#!/usr/bin/perl -w use strict; open FILEHANDLE , "$filename" or die "cannot open the file : $filename + :$!"; my @array = <FILEHANDLE>; foreach ( @array ) { chomp $_; #This Chomp plays an important role here; sleep 1; print "$_"; #But this line does some thing strange. } close FILEHANDLE ;
In the above code, If i comment the
chomp $_;
The sleep function executes first then it prints the contents of the file. But where as if I uncomment the line, (i.e) i didn't remove the new line char at the end of the file contents, it is doing good.
Can you ppl able to guess why it does so ? Nowhere they have mentioned about sleep's this behavious. What may be the relation ship with the sleep and the newline entry ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is the wrong with the sleep function ?
by Aristotle (Chancellor) on Dec 30, 2005 at 09:11 UTC | |
|
Re: What is the wrong with the sleep function ?
by TedPride (Priest) on Dec 30, 2005 at 09:32 UTC | |
|
Re: What is the wrong with the sleep function ?
by runrig (Abbot) on Dec 30, 2005 at 09:13 UTC |