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
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=~/(?:##startof
push @msgs, $1;
}
foreach(@msgs)
{
while($_=~/([^:]+)::\n?([^
$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