473,837 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

65 New Member
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
1 2269
nithinpes
410 Recognized Expert Contributor
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

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

Similar topics

2
1638
by: blip | last post by:
Is this acceptable ? It seems too easy and too simple... #include<iostream> #include<fstream> #include<cstdlib> #include<string> struct Person{ char name ; int age ;
4
11372
by: TT (Tom Tempelaere) | last post by:
Hi, In my project I need to use VirtualAlloc (kernel32) to allocate memory to ensure that data is 4K aligned. I need to fill the data block with file contents. I notice that there are no 'Read' operations to memory pointed to be an IntPtr (I checked FileStream & BinaryReader). Can I do this from C#/.NET? I'm currently mapping C-functions to achieve this, and I'm not too fond of doing that. Can someone help me with this?
4
3433
by: Gustaf Liljegren | last post by:
This may be a question of taste, but if there is a best practice, I want to know. I have two choises: SomeClass s = new SomeClass(file); // Load the file or SomeClass s = new SomeClass(); s.Load(file); // Load the file
15
3663
by: Gan Quan | last post by:
I'm writing a c++ program that has many (100+) threads read/write files simultaneously. It works well if not considering the efficiency. The file i/o seems to be the bottleneck. This is my code to read from and write to files: #include <fstream> #include <sstream> #include <string>
2
1152
TheMadMidget
by: TheMadMidget | last post by:
I'm trying to use something like file_get_contents() but on a file that requires a username and password. Thanks, Jason
2
3008
by: lab3terch | last post by:
I am a student finishing a class in Visual Basic, and would like some assistance with a program I am working on. I need to read the contents of a file (showing makes of cars on one line and a daily rental fee on the following line) into an array and then display the file contents in a list box. The user then chooses the car he/she wants to rent. I then need to obtain the rental fee from the array and use that value to calculate the total...
2
951
by: =?Utf-8?B?SGFyaXNo?= | last post by:
I am doing file operations using fopen(), fwrite(), fclose() group of functions. At times I need to clear the file contents while the file is open. Is there a function in the same group to do it? (Or a workaround other than closing and reopening the file in write mode?) --Harish
6
1251
by: nnamakaonwodi | last post by:
I have a file that I want to read. The structure is given in C++ eg. typedef HEADER_TAG { UCHAR index; UCHAR crt; }HEADER_TAG
4
4665
aryanraj
by: aryanraj | last post by:
Hi Everybody, I want to design an html file viewer, for that i have got the code to browse the file, but i am not able to read the contents of the selected file, can anybody help to open the file and read it contents and display the content into the textarea. Thanks in advance, Aryan.
2
1793
by: amollokhande1 | last post by:
Hi, I am trying to read the file contents using System.IO.File.ReadAllText After reading the file contents the special charaters (á) gets replaced with some garbage characters like "?". To elliminate this I have used encoding along with above method System.IO.File.ReadAllText(strFile, System.Text.Encoding.ASCII) But still it is not working.Can anybody have the solution for this
0
9847
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9693
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10899
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10583
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9419
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7824
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.