471,830 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,830 software developers and data experts.

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

Hi Everyone,

i have the written this logic :
basically a file operation

Expand|Select|Wrap|Line Numbers
  1. open (CONFIGFILE, "$config_file") or die;
  3. while (<CONFIGFILE>) {    
  4.     chomp;
  6.     if ( ! ( $_ =~ /^#/ ) ) {
  7.        $CONFIG = $CONFIG . $_ . " ";
  8.     }
  9. }
  10. close (CONFIGFILE);
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 ??

Sep 15 '08 #1
1 2168
410 Expert 256MB
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. }
Sep 15 '08 #2

Post your reply

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

Similar topics

2 posts views Thread by blip | last post: by
4 posts views Thread by Gustaf Liljegren | last post: by
2 posts views Thread by =?Utf-8?B?SGFyaXNo?= | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.