[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Regular Expression Definition



>I am trying to 'split' the following line:
>
><ASCII 10> YY,XX   BIN #  1-IDSXP   #  2-VGS1P   #  8-IGSO    # 10-VGF    \n
>          ^     ^^^   ^ ^^       ^^^ ^^       ^^^ ^^      ^^^^ ^      ^^^^
>where ^ = whitespace.  I need the line to be place into the array as follows:
>
>[YY,XX] [BIN] [#  1-IDSXP] [#  2-VGS1P] [#  8-IGSO] [# 10-VGF]
>                ^^           ^^           ^^          ^
>so that the numerical data lines that follow will correlate (array
>index-wise) with these headers.  I have tried various combos of /s, etc.,
>but the varying whitespaces are reeking havoc.  Sometimes, I will also
>end up with the fist element of the array containing the NULL character.

It depends on what you are trying to "split" on, and what defines each element. 
Is each element shown above in braces, or is the whole line a single element? 
In any case, you will probably use a function to deal with the variable spaces. 
The built-in functions pack/unpack, formats, and sprintf may server you here,
depending on the conditions of source data and output.  An example could be
(making certain assumptions about reliability of data):

s/^.*?(YY,XX).*?#/\1:BIN#/;
s/\s+//g;
s/#(\d+)/sprintf("\t#%3d", $1)/eg;
s/:/\t/g;

split /\t/;

__END__

Alex

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch