Solved

Split this field

Posted on 2001-06-15
5
157 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
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
bebonham earned 70 total points
Comment Utility
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
Comment Utility
bebonham,
Excellent performance.
Thanks a lot
0
 

Author Comment

by:r_kar
Comment Utility
bebonham,
Excellent performance.
Thanks a lot
0
 
LVL 8

Expert Comment

by:bebonham
Comment Utility
hey, glad to be of help!

your welcome.
0
 
LVL 8

Expert Comment

by:bebonham
Comment Utility
hey, glad to be of help!

your welcome.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now