473,385 Members | 1,409 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,385 software developers and data experts.

string parsing in perl

18
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 6999
KevinADC
4,059 Expert 2GB
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
Thanks kevin i will come back with more info
Sep 4 '07 #3
jjeanj1
18
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
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...
0
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...
4
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
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...
4
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...
5
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...
2
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,...
1
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...
1
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 &...
3
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,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.