473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Data extraction in Perl

I have a below line in file '/data/control.dat'..

migration.MW05152013/nm16,CDW

I want to fetch only migration.MW05152013/nm16

Below is the code, But it is fetching full line. Can you help on this.

Expand|Select|Wrap|Line Numbers
  1. $CONTROL_FILE=/data/control.dat
  2.         open (CONTROL_FILE, "<$CONTROL_FILE") or handle_error(open_control_file);
  3.  
  4.         while ( $ENTRY = <CONTROL_FILE> )
  5.         {
  6.                 if ( $ENTRY =~ /^(.*?)\s/ )
  7.                 {
May 15 '13 #1
3 1799
RonB
589 Expert Mod 512MB
Try changing your regex to this:
Expand|Select|Wrap|Line Numbers
  1. /^([^/]+)/
May 15 '13 #2
Oralloy
988 Expert 512MB
v2k,

Are you trying to read a partial line, or extract the desired information at line 6 of your code sample?

[RonB] I think he wants to break at the comma, not a stroke.

This might do what you need, if you insert it above line 6:
Expand|Select|Wrap|Line Numbers
  1. ($ENTRY,$rest) = ($ENTRY =~ m/([^,]*),(.*)/);
Cheers,
Oralloy
May 17 '13 #3
RonB
589 Expert Mod 512MB
Oralloy, you're right. I need to start wearing my glasses. ;o)

I'd probably end up using split.

Expand|Select|Wrap|Line Numbers
  1. my $CONTROL_FILE = '/data/control.dat';
  2.  
  3. open my $ctrl_fh, '<', $CONTROL_FILE or handle_error("open_control_file <$!>");
  4.  
  5. while ( my $line = <$ctrl_fh> ) {
  6.  
  7.     my $entry = (split(/,/, $line))[0];    
  8.     # do whatever is needed with $entry 
  9.  
  10. }
  11.  
May 17 '13 #4

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

Similar topics

1
by: Jason Huang | last post by:
Hi, To make it short, how do we do the data extraction to MSWord using ASP.Net C#? Any help will be appreciated. Jason
2
by: Jason Huang | last post by:
Hi, Would someone show me how to do the data extraction to Excel in ASP.Net using C# web form? I am not familiar with VB, so I am asking someone to help me out! Any help will be appreciated. ...
1
by: KenB | last post by:
I have data from a clinical trial, where each record has been stored on a network drive in (of all things) a MS Word document. The documents were created with a template, so the location of the...
0
by: rsarwar | last post by:
What is the best way to extract data from another system and place the same data into another, woyuld a ;possible solutuion be creating a xml document to transfer data?
4
by: freeurmind | last post by:
hello everybody, i'm trying to read binary data from an input file and store their bit by bit representation in an int array for further manipulation: - using the file.read(buffer,1) to retrieve my...
5
KevinADC
by: KevinADC | last post by:
Introduction This discussion of the sort function is targeted at beginners to perl coding. More experienced perl coders will find nothing new or useful. Sorting lists or arrays is a very common...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
0
by: Amitava Maity | last post by:
Hello, I have a data file (data.csv) that is something like this: data, Conductor, ACSR data, diameter, 0.02862 data, cross-section, 0.0004845 data, weight, 1.621 data, Mod, 7000000000...
2
by: 0658 | last post by:
Public Class Form1 Dim n As Integer = 0 Dim m As Integer = 0 Dim s As String Dim x As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As...
3
by: blackdevil | last post by:
hi, I have three arrays with variable values from a netCDF file. xy contains the vectors for the lon and lat coordinates. I am extracting the coordinates out of the two arrays (lon, lat) according...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.