?
Solved

Split this field

Posted on 2001-06-15
5
Medium Priority
?
196 Views
Last Modified: 2010-03-05
Hi all,
I would like to read this text file and store  it on different variable. Each set of data is separated by
##startoffile## and ##endoffile## . I can read this file .. spliting and storing is not done.

The value will be stored as
password= saV9ejDMWuP92.

sub=Hello
msg=Hi there
name=Xavier
date=Fri Jun 15 07:09:57 2001
saV9ejDMWuP92

sub=test
msg=test message1
name=Stefen
date= Fri Jun 15 07:11:32 2001
       
sub=Btech
msg=New Message from usa
name=George
date=Fri Jun 15 07:13:33 2001

sub=hi
msg=hello
name=Alex
date=Fri Jun 15 07:32:56 2001

-------------------------------------------------
Text file starts from here..
-----------------------------------


saV9ejDMWuP92

##startoffile##
Subject::Hello
From::Xavier
Message::
Hi there
Time::  Fri Jun 15 07:09:57 2001
##endoffile##
Subject::test
From::Stefen
Message::
test message1
Time::  Fri Jun 15 07:11:32 2001
##endoffile##
Subject::Btech
From::George
Message::
New Message from usa
Time::  Fri Jun 15 07:13:33 2001
##endoffile##
Subject::hi
From::Alex
Message::
hello
Time::  Fri Jun 15 07:32:56 2001
##endoffile##

------------------------

Pls provide the solution as early as possible.
Thanks
0
Comment
Question by:r_kar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 280 total points
ID: 6195644
didn't seem too easy...
but try this script:



open FILE, "parse.txt";
my $file='';
my @f=<FILE>;
foreach(@f){
$file.=$_;
}

$file=~/([^ \t\n\r]+)[\n\r\t ]*##startoffile##/s;
$pw=$1;
while($file=~/(?:##startoffile##)?([^#]+)##endoffile##/sg){
push @msgs, $1;
}
foreach(@msgs)
{
while($_=~/([^:]+)::\n?([^\n]+)\n/sg){
$v=$1;
chomp($l=$2);
$l=~s/\n//;
push( @{ $mail{$v} }, $l)
}}

print "password: $pw\n\n";

for($i=0;$i<$#msgs;$i++)
{
foreach(sort keys %mail)
{
print $_ . " = " . $mail{$_}->[$i] . "\n";
}
print "\n\n";
}



Bob
0
 

Author Comment

by:r_kar
ID: 6209368
bebonham,
Excellent performance.
Thanks a lot
0
 

Author Comment

by:r_kar
ID: 6209373
bebonham,
Excellent performance.
Thanks a lot
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6212449
hey, glad to be of help!

your welcome.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6212450
hey, glad to be of help!

your welcome.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question