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

Re: Re(2): [MacPerl] Regular Expression Definition



>At 20:52 -0800 11/6/98, Mark Yannuzzi wrote:
>>I was unaware that whitespace had this specific a definition, i.e., that
>>you cannot have two adjacent instances of whitespace...this is helpful to
>>know...specifically,

As a clarification, 'cause I was a little confused by this:  the definition of
"whitespace" is one or more spaces, tabs, or newlines (essentially--there may be
more characters in this set).  The '\s' sequence in a regex, on the other hand,
specifies only one instance of a whitespace character.  I am probably the only
person to take it this way, but just in case :-)

>>>  *  the fields are bounded within certain column positions
>>   -  a little unclear are what you mean, the extrema are the beginning
>>      <ASCII 10> and the ending \n...I think, however, that the columns
>>      that begin with a '#' may be limited to 12 characters (leaving a
>>      single space between the preceeding and following column.  The
>>      spacing between before and after the "YY,XX" and "BIN" columns
>>      are constant.

<snip>

>  chomp($line);                         # strip off newline
>  $line = substr($line, 2);             # strip off leading junk
>  @fields = split($line);               # split on whitespace

Just an aside, but splitting on whitespace by omitting the pattern parameter
only works when the variable is omitted as well (and $_ is used).  Change $line
to $_ and it works peachy as long as "split" is used instead of split($_) which
does something entirely different.

>>I was trying to do this with a single use of the "split" function, which
>>is what prompted my initial e-mail...perhaps this is not possible.

It probably is possible, because of the flexibility of Perl syntax, but it
probably won't be pretty.  I have used {} syntax when parsing fixed-length data
in the past.  A somewhat esoteric solution could be:

@fields = (/(\S\S,\S\S)\s+(BIN)\s+/, /(#.{9})\s+/g);


-Alex

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