Thanks Ee and Bill,
Both your solution work perfectly for the data set that I provided.
However I think I missed in explaining an important point.
The sample was only one file out of thousands of file that need to be
parsed. See attached as another example which shows what I mean to say.
This is where I am getting stuck as the "field width is not constant".
(It changes in different files based on the max length of the data in a
particular field).
Any thoughts on making a generic parser script to create an array for
this?
Thanks
Sushil
________________________________
From: Lim Ee Wah [mailto:[EMAIL PROTECTED]
Sent: Friday, August 10, 2007 7:27 PM
To: Negi, Sushil (MED US)
Cc: [email protected]
Subject: Re: Splitting String in array
You can try this:
while (<DATA>)
{
my @array = ( /(\w{3}\_\d{3}) \s
(.{4}) \s
(.{9}) \s
(.{4}) \s{6}
(.{12}) \s
(.{29}) \s
(.*$)
/x );
@array = map {s/^\s*|\s*$//g;$_} @array;
for (0..6)
{
print "\$array[\$_] = \"$array[$_]\"\n";
}
print "\n";
}
__DATA__
ABC_011 0311 0311 Pat Asc FirstName LastName
MiddleName ABCAHS: no City present, City Required...
ABC_010 V9D2 0310 0311 Requires FirstName MiddleName
SANAH 3.0x - 55+ User Fields UI- : no feature.
ABC_000 0903 9.0a1 0903 Pat Asc FirstName LastName
blah blah blah Series Timeframe max
ABC_579 0903 0303_AB99 0311 Cat Dog LastName
MiddleName Serivce Summarisation not option sorting by Date.
ABC_707 0903 0311
SRFDSA0142\\///SS:NullPointerException:mark incomplete
ABC_707 0903
SRFDSA0142\\///SS:NullPointerException:mark incomplete
On 8/11/07, Negi, Sushil (MED US) <[EMAIL PROTECTED] > wrote:
Hi guys,
I need some help in splitting the strings from the attached file
(or below data). The attached file also contains the example output
arrays. I am probably done with looking at this since morning. Any help
will be greatly appreciated.
-------------------------------------------------------------------
Pattern to be Parsed is below
ABC_011 0311 0311 Pat Asc FirstName
LastName MiddleName ABCAHS: no City present, City Required...
ABC_010 V9D2 0310 0311 Requires FirstName
MiddleName SANAH 3.0x- 55+ User Fields UI- : no feature.
ABC_000 0903 9.0a1 0903 Pat Asc FirstName
LastName blah blah blah Series Timeframe max
ABC_579 0903 0303_AB99 0311 Cat Dog
LastName MiddleName Serivce Summarisation not option sorting by Date.
ABC_707 0903 0311
SRFDSA0142\\///SS:NullPointerException:mark incomplete
ABC_707 0903
SRFDSA0142\\///SS:NullPointerException:mark incomplete
Below is the expected results
from
ABC_011 0311 0311 Pat Asc FirstName
LastName MiddleName ABCAHS: no City present, City Required...
@array [0]="ABC_011"
@array [1]="0311"
@array [2]=""
@array [3]="0311"
@array [4]="Pat Asc"
@array [5]="FirstName LastName MiddleName"
@array [6]="ABCAHS: no City present, City Required..."
from
ABC_000 0903 9.0a1 0903 Pat Asc FirstName
LastName blah blah blah Series Timeframe max
@array [0]="ABC_000"
@array [1]="0903"
@array [2]="9.0a1"
@array [3]="0903"
@array [4]="Pat Asc"
@array [5]="FirstName LastName"
@array [6]="blah blah blah Series Timeframe max"
from
ABC_579 0903 0303_AB99 0311 Cat Dog
LastName MiddleName Serivce Summarisation not option sorting by Date.
@array [0]="ABC_579"
@array [1]="0903"
@array [2]="0303_AB99"
@array [3]="0311"
@array [4]="Cat Dog"
@array [5]="LastName MiddleName"
@array [6]="Serivce Summarisation not option sorting by Date."
Thanks
Sushil
------------------------------------------------------------------------
----
This message and any included attachments are from Siemens Medical
Solutions
and are intended only for the addressee(s).
The information contained herein may include trade secrets or privileged
or
otherwise confidential information. Unauthorized review, forwarding,
printing,
copying, distributing, or using such information is strictly prohibited
and may
be unlawful. If you received this message in error, or have reason to
believe
you are not authorized to receive it, please promptly delete this
message and
notify the sender by e-mail with a copy to
[EMAIL PROTECTED]
Thank you
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
----------------------------------------------------------------------------
This message and any included attachments are from Siemens Medical Solutions
and are intended only for the addressee(s).
The information contained herein may include trade secrets or privileged or
otherwise confidential information. Unauthorized review, forwarding, printing,
copying, distributing, or using such information is strictly prohibited and may
be unlawful. If you received this message in error, or have reason to believe
you are not authorized to receive it, please promptly delete this message and
notify the sender by e-mail with a copy to [EMAIL PROTECTED]
Thank youFile 1
ABC_011 0311 0311 Pat Asc FirstName
LastName MiddleName ABCAHS: no City present, City Required...
ABC_010 V9D2 0310 0311 Requires FirstName
MiddleName SANAH 3.0x- 55+ User Fields UI- : no feature.
ABC_000 0903 9.0a1 0903 Pat Asc FirstName
LastName blah blah blah Series Timeframe max
ABC_579 0903 0303_AB99 0311 Cat Dog
LastName MiddleName Serivce Summarisation not option sorting by Date.
ABC_707 0903 0311
SRFDSA0142\\///SS:NullPointerException:mark incomplete
ABC_707 0903
SRFDSA0142\\///SS:NullPointerException:mark incomplete
File 2 (See here field length is changed based on the reduced size of the data
that is going in the field)
ABC_011 0311 0311 Pat A FirstName LastName ABCAHS: no
City present, City Required...
ABC_010 V9D2 0310 0311 Req FirstName MiddleName SANAH 3.0x-
55+ User Fields UI- : no feature.
ABC_000 0903 9.0a1 0903 Pat FirstName LastName blah blah
blah Series Timeframe max
ABC_579 0903 0311 Cat LastName MiddleName Serivce
Summarisation not option sorting by Date.
ABC_707 0903 0311
SRFDSA0142\\///SS:NullPointerException:mark incomplete
ABC_707 0903
SRFDSA0142\\///SS:NullPointerException:mark incomplete
File 3 (See here field length is changed based on the reduced size of the data
that is going in the field)
ABC_000 0903 9.0a1 0903 Pat FirstName LastName
blah blah blah Series Timeframe max
ABC_579 0903 0303_AB99 0311 Cat Dog FirstName LastName
MiddleName Serivce Summarisation not option sorting by Date.
ABC_707 0903 0311
SRFDSA0142\\///SS:NullPointerException:mark incomplete
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs