By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,712 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,712 IT Pros & Developers. It's quick & easy.

Need to terminate the looping after reading the file contents!!!!!

P: 65
Hi Everyone,

i have the written this logic :
basically a file operation

Expand|Select|Wrap|Line Numbers
  1. open (CONFIGFILE, "$config_file") or die;
  2.  
  3. while (<CONFIGFILE>) {    
  4.     chomp;
  5.  
  6.     if ( ! ( $_ =~ /^#/ ) ) {
  7.        $CONFIG = $CONFIG . $_ . " ";
  8.     }
  9. }
  10. close (CONFIGFILE);
  11.  
Note: Config file(text file) has some text lines<br>

now my problem is :
Config file has some 10 to 15 lines but the above code run for a while even after reading all the line from the file.

now i need some sort of logic where i can terminate the looping once it finishes the reading the line or it encounter the some specail character or keep some wait_time variable & loop till wait_time exceeds.

Can anyone help me on how to achieve above said logic ??

i need to alter this code to suit the above said requirement
can anyone help me on this ??

Regards,
Vijayarl
Sep 15 '08 #1
Share this Question
Share on Google+
1 Reply


nithinpes
Expert 100+
P: 410
If you want to terminate the loop after a particular requirement is met, you may use the last statement.e.g
Expand|Select|Wrap|Line Numbers
  1. while(<FILE>) {
  2.  if(/$pat/) {
  3.   my $str= $_;
  4.   last;  ## comes out of while loop
  5.   }
  6. }
  7.  
Sep 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.