467,883 Members | 1,245 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,883 developers. It's quick & easy.

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;
  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
  • viewed: 2046
Share:
1 Reply
nithinpes
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. }
  7.  
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 MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.