473,545 Members | 2,009 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 2243
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
1626
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
11357
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...
4
3400
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
3633
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
1142
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
2989
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...
2
940
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
1236
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
4655
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
1781
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...
0
7409
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...
0
7664
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. ...
0
7921
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...
1
7437
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...
0
7771
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5982
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...
1
5343
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...
0
3465
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...
0
720
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...

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.