473,598 Members | 3,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string parsing in perl

18 New Member
i have a text file with lines as such:

Paul simon robert jones
eddy Rick dave smith paul

where paul simon could be the First name.

and Robert Jones could be the last name.

i need a split routine that would capture these field. Please help
Sep 4 '07 #1
3 7010
KevinADC
4,059 Recognized Expert Specialist
All you really have to do is split the lines on the spaces(s)

@fields = split(/\s+/,$line)

where $line is each line of the file as you loop through it. Please post the code you have tried so far fr more help or read a perl tutorial:

http://www.perl.org/books/beginning-perl/
Sep 4 '07 #2
jjeanj1
18 New Member
Thanks kevin i will come back with more info
Sep 4 '07 #3
jjeanj1
18 New Member
This is he formart of the file with many more entries.

Expand|Select|Wrap|Line Numbers
  1. E 100200 A Gizzi  Avila         aldo gonzalo 
Expand|Select|Wrap|Line Numbers
  1. E 1023877 A Arias Briones       Claudio Andres

now i need to be able to capture from each line :

100200--> employee number

Action--> A

Last name--> Gizzi Avila (that's the tricky part)

First Name---> Aldo gonzalo (That's the tricky part)


now this is the code that i have

Expand|Select|Wrap|Line Numbers
  1. $UNIXFILE = "unixinfo.txt";
  2. open(UNIXFILE) or die("Could not open UNIX FILE.");
  3. foreach $line (<UNIXFILE>) {
  4.  
  5. ($e,$id,$action,$first_name,$name)=split(/\s+/ ,$line);
  6.  
  7. #print" $e";
  8.  
  9. print"employee id: $id ";
  10.  
  11. print"Action: $action ";
  12.  
  13. print"First Name: $first_name ";
  14.  
  15. print"$name\n";
  16.  
  17. }
  18. close(UNIXFILE);
NOtice that the last name and first name can have up to 3 diffren names and i need to capture that as on name.
Sep 4 '07 #4

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

Similar topics

8
4423
by: Jean-Marie Vaneskahian | last post by:
Reading - Parsing Records From An LDAP LDIF File In .Net? I am in need of a .Net class that will allow for the parsing of a LDAP LDIF file. An LDIF file is the standard format for representing LDAP objects. I need to be able to read the records from an LDIF file into ..Net. There exists a Perl module that will do exactly this called Net::LDAP::LDIF but I am wanting to port my code over to .Net and cannot find anything with similar...
0
1399
by: kellner | last post by:
Hello, I'm parsing a chunk of XML code and would like to add attribute values to individual tags if these are lacking. This is with perl 5.8.6, libxml2 2.6.17, XML::LibXML 1.58. Basically, I have the parser add the attribute values to the respective nodes and then use the toString method of XML::LibXML::Document to write the modified text to a scalar. Both the original and the modified text evaluate properly as utf8, but the modified...
4
2133
by: Gary Wessle | last post by:
Hi how can I do this in C++ string myword; string get_word_from_this_url( url ){ bool flag = true; while flag; download this url and search for this word; if found; set flag to false;
1
1758
by: Robert Neville | last post by:
Basically, I want to create a table in html, xml, or xslt; with any number of regular expressions; a script (Perl or Python) which reads each table row (regex and replacement); and performs the replacement on any file name, folder, or text file (e.g. css, php, html). For example, I often rename my mp3 (files); the folder holding the mp3 files; and replace these renamed values in a playlist/m3u/xml file. The table should hold clean...
4
3922
by: R Wood | last post by:
Greetings - A recent Perl experiment hasn't turned out so well, which has piqued my interest in Python. The project is this: take a Vcard file exported from Apple's Addressbook and use a language that is good at parsing text to convert it into a mutt alias file. There are better ways to use Mutt with Mac's addressbook, but I want to be able to periodically convert my working addressbook file into an alias file I can then transfer...
5
2326
by: moddster | last post by:
Hi Guys. I am a newbie to perl and need some help with a problem. PROBLEM: I have to parse an HTML file and get rid of all the HTML tags and count the number of sumbissions a person has through out the dates found. The condition is that multiple submissions by the same person on the same date is counted as 1. I have already gotten rid of the HTML tags using: #!/usr/bin/perl -w use strict;
2
2425
by: Gary42103 | last post by:
Hi I need Perl Script to do Data Parsing using existing data files. I have my existing data files in the following directory: Directory Name: workfs/ams Data File Names: 20070504.dat, 20070503.dat, 20070502.dat In each of above data files there will be some millions of records. So my job is read those data files and also read first 3 letters of each record in all above data files and write into new data files.For example
1
2480
by: worlman385 | last post by:
I need to parse the following HTML page and extract TV listing data using VC++ http://tvlistings.zap2it.com/tvlistings/ZCGrid.do any good way to extract the data? is easy for VC++ to call PERL script and do some regular expression? since the HTML page is not XML well formed, I cannot use a XML parser
1
2827
by: andrewwan1980 | last post by:
I need help in parsing unicode webpages & downloading jpeg image files via Perl scripts. I read http://www.cs.utk.edu/cs594ipm/perl/crawltut.html about using LWP or HTTP or get($url) functions & libraries. But the content returned is always garbled. I have used get($url) on a non-unicode webpage and the content is returned in perfect ascii. But now I want to parse http://www.tom365.com/movie_2004/html/5507.html and the page I get back is...
3
1389
by: James Kanze | last post by:
On Sep 12, 7:25 am, Ruben <ru...@www2.mrbrklyn.comwrote: You can specify a delimitor when calling getline, but I'd tend to consider that a bit abuse. I'd just parse the string directly, rather than using stringstream. Possibly with boost::regex, but something as simple as the following should work:
0
7991
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
7902
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
8395
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
8265
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6719
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
5850
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
3898
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...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.