CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help needed...quick...appreciate very much

 



abcxyz778
New User

Jun 18, 2006, 4:29 AM

Post #1 of 2 (518 views)
Help needed...quick...appreciate very much Can't Post

I have a file with about a 1000 or more records in the following format(this is one record,imagine it all in one line):

5/31/2006 0:00:00|"EMS"|"mBlox"|"25255"|"Alltel"|"0014172290558"|38.00|43.00|"Sexy"|"How bout tellin me yah name now =)"|"Hi there sexy thing.. wanna talk?"|4/30/2006 23:40:48|4/30/2006 0:00:00|5/1/2006 17:51:32|5/1/2006 0:00:00|4/30/2006 23:43:22|4/30/2006 0:00:00|"out"||37.62|42.57|"31 - 60 Days"|"21 - 40"|"Less than $50.99"|31.00

But some of the records are cut off for some reason like this(it's cut off after "Sexy and the rest of it shows as a new record):

5/31/2006 0:00:00|"EMS"|"mBlox"|"27772"|"Alltel"|"0014802043951"|1.00|1.00|"Sexy
''CLOWNIN AROUND''"|"ohh ok here from New Mexico how old are you whar is your name?"|"ohh ok here from New Mexico how old are you whar is your name?"|5/1/2006 7:36:49|5/1/2006 0:00:00|5/1/2006 9:58:25|5/1/2006 0:00:00|5/1/2006 9:58:25|5/1/2006 0:00:00|"out"||0.99|0.99|"Less than 30 Days"|"Less than 20"|"Less than $50.99"|30.00

What i want to do now is write a perl script which processes this file so that when each line in the file does not start with the date,then merge it with the previous line i.e., the ENTER key character needs to be gone...hope you understand my question.
I'm new to PERL and have no idea on how to implement this...can someone help.Thank you very much!


davorg
Thaumaturge / Moderator

Jun 19, 2006, 5:37 AM

Post #2 of 2 (513 views)
Re: [abcxyz778] Help needed...quick...appreciate very much [In reply to] Can't Post

(It's "Perl", not "PERL")

You probably want something like this. It reads from STDIN and writes to STDOUT.


Code
my $prev; 
while (<>) {
chomp;
if (m|^\d\d?/\d\d?/\d\d\d\d|) {
print "$prev \n"if defined $prev;
$prev = $_;
} else {
$prev .= "|$_";
}
}
print "$prev \n"if defined $prev;


By the way, you have very bizarre looking dates :-)

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives